debschofield
New Member
- Joined
- Oct 1, 2019
- Messages
- 10
I'm very new to macros so please be gentle with me!
I'm trying to set up a series of worksheets to copy and paste raw data that is filtered from a main workbook into different cost centres and then update the various pivot tables. Unfortunately I don't think I have fully understood the way to write my code. I have tried to insert variable ranges for the copy and paste areas that will change each month but have then been getting various errors about objects and subscript and now the one i have captured in the image below
Sub CarLeasingPivot()' This is a copy of the recorded macro to test writing in VBA
'
' Im setting a dimension to automatically find the last free row in a data range
Dim lr As Long
' to get the last filled row in column A then the formula is
lr = Cells(Rows.Count, "A").End(xlUp).Row
'Print lr's value to the immediate Window
Debug.Print lr
Sheets("GL Raw Data").Range("A1:X" & lr).AutoFilter Field:=10, Criteria1:="505080" (this gets run time error 438 object doesn't support this property or method)
'The range below was originally the number of rows recorded in the macro but we need this to be dynamic so that
'it will change every month with the number of entries that are received.
Range("A1:U" & lr).Copy
Sheets("Car lease data").Range("A1" & lr).Paste
Sheets("Car Leases 505080").Select
ActiveWorkbook.RefreshAll
Sheets("Car lease data").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Car Leases 505080").Select
ActiveWindow.ScrollWorkbookTabs Sheets:=-2
Sheets("Header").Select
End Sub
Can anyone offer some advice??
Many thanks
Deb
I'm trying to set up a series of worksheets to copy and paste raw data that is filtered from a main workbook into different cost centres and then update the various pivot tables. Unfortunately I don't think I have fully understood the way to write my code. I have tried to insert variable ranges for the copy and paste areas that will change each month but have then been getting various errors about objects and subscript and now the one i have captured in the image below
Sub CarLeasingPivot()' This is a copy of the recorded macro to test writing in VBA
'
' Im setting a dimension to automatically find the last free row in a data range
Dim lr As Long
' to get the last filled row in column A then the formula is
lr = Cells(Rows.Count, "A").End(xlUp).Row
'Print lr's value to the immediate Window
Debug.Print lr
Sheets("GL Raw Data").Range("A1:X" & lr).AutoFilter Field:=10, Criteria1:="505080" (this gets run time error 438 object doesn't support this property or method)
'The range below was originally the number of rows recorded in the macro but we need this to be dynamic so that
'it will change every month with the number of entries that are received.
Range("A1:U" & lr).Copy
Sheets("Car lease data").Range("A1" & lr).Paste
Sheets("Car Leases 505080").Select
ActiveWorkbook.RefreshAll
Sheets("Car lease data").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Car Leases 505080").Select
ActiveWindow.ScrollWorkbookTabs Sheets:=-2
Sheets("Header").Select
End Sub
Can anyone offer some advice??
Many thanks
Deb