Beginner in VBA and I am having a compile error object not required for the following code

ambepat

Board Regular
Joined
May 4, 2014
Messages
127
I am getting a "compile error object required" at set lastrow. Not sure how to fix it so any help will be really appreciated. Thanks.

Sub copydata()

Dim lastrow As Long
Dim CrossTBrow
Dim i As Long




Set lastrow = Worksheets("Trial Balance").Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To lastrow


Worksheets("Trial Balance").Cells(i, 1).Copy
CrossTBrow = Worksheets("Cross Tabular Raw Data").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

Worksheets("Trial Balance").Paste Destination:=Worksheets("Cross Tabular Raw Data").Cells(CrossTBrow, 1)



Next i
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Remove the word "Set"

Code:
lastrow = Worksheets("Trial Balance").Cells(Rows.Count, 1).End(xlUp).Row
 
Upvote 0
Remove the word "Set"

Code:
lastrow = Worksheets("Trial Balance").Cells(Rows.Count, 1).End(xlUp).Row

Hi Michael,

Thanks for your reply.

When I remove the set I have a Run-time error 9 - Subscript out of range. Also please explain why you will remove the set?

Thanks for your help. Really appreciate it.
 
Upvote 0
Code:
"Subscript out of range"
Usually means that one of your sheets names in the code doesn't match the actual Sheet name...check for typos, spelling, and excess spaces...leading or trailling.

Have a look at this link to get a better understanding of the "Set" keyword.
It is used to create a new object, but in your case you only need to return an Integer value



https://stackoverflow.com/questions/349613/what-does-the-keyword-set-actually-do-in-vba
 
Upvote 0
Code:
"Subscript out of range"
Usually means that one of your sheets names in the code doesn't match the actual Sheet name...check for typos, spelling, and excess spaces...leading or trailling.

Have a look at this link to get a better understanding of the "Set" keyword.
It is used to create a new object, but in your case you only need to return an Integer value



https://stackoverflow.com/questions/349613/what-does-the-keyword-set-actually-do-in-vba


Thanks for you help. Appreciate it.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,681
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top