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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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