runtime error

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings,
I noticed that that "offsets" are used by a lot of you when you are ranging userforms and input boxes. It seems like a pretty good technique to use instead of hard coding ranges so I thought that I would start learning this. If I understand this correctly the first column is the row and the second number is the column, pretty straight forward. However, I am getting a runtime error when I try to use this so apparently I am missing something.

For example, if I am trying to send my data to the "next blank" row. I thought that I would use this string, but I get a runtime error...

Code:
Range("A1").End(xlDown).Offset(1, 0).Select


This string does not give me a runtime error, but the data ends up in B1048576 - I get the "B" column, but zero gives me the last row in the worksheet?

Code:
Range("A1").End(xlDown).Offset(0, 1).Select

Would anyone mind explaining what is wrong with the initial string? Thank you for any insight.
 

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.
IF the xlDown from A1 takes you to the lasts cell (A1048576), then the error is in trying to go one more row down (Offset(1,0)) which doesn't exist.

Range("A1").end(xldown) would take you to A1048576, then Offset(0,1) would be B1048576.
 
Upvote 0
oh, of course - that makes total sense (I should have picked up on that myself because I tried 0,0, and got that exact result that you are describing). But what would be the right number to use for the next row?

I guess I am confused because if (0,1) takes me to column "B", why doesn't (1,0) take me to Row 2? I didn't type in (1048576,1) to the string....
 
Upvote 0
With your current code
Code:
Range("A1").End(xlDown).Offset(1, 0).Select
you are trying to get the next row of last row in the sheet, which causes an error.

If you want to get the cell in next row, then write
Code:
Range("A1").Offset(1, 0).Select
 
Upvote 0
Oh, okay - so the xlDown takes you to the end of the WS, I thought it just meant "down". Thank you both for the knowledge, it is very appreciated.
 
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