Simple line of code generating run time error

Scott JS

New Member
Joined
Aug 3, 2005
Messages
35
The following code, which works in other macros, is causing a “Run-time error ‘1004’: Application-defined or object-defined error"

  1. Cells(20000,1).Select
  2. Selection.End(x1Up).Select
  3. Let lastrow = Activecell.Row

The debugger is highlighting row 2 -- the equivalent of a manual “end then up arrow” as the problem code. ?????????
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Not x1 up, but xlup.

Furthermore, you don’t need selects in VBA and “let” is actually always omitted.
 
Upvote 0
Not x1 up, but xlup.

Furthermore, you don’t need selects in VBA and “let” is actually always omitted.
Re the let -- thanks, will amend, but I'm not even getting that far
re the 1 vs. the l, that fixed it. Thank you!
 
Upvote 0
The following code, which works in other macros, is causing a “Run-time error ‘1004’: Application-defined or object-defined error"

  1. Cells(20000,1).Select
  2. Selection.End(x1Up).Select
  3. Let lastrow = Activecell.Row

The debugger is highlighting row 2 -- the equivalent of a manual “end then up arrow” as the problem code. ?????????
That can all be simplified to a single line:
VBA Code:
lastrow = Cells(20000,1).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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