Finding last used row in non-contingous data using column number (not letter)

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
So this is the oldest (or one of them) trick in the book with
VBA Code:
lRow = ThisWorkbook.Worksheet("Sheet1").Range("A" & Rows.Count).End(xlUp).Row

But what I'm working with is a column number (say 15). Can I use the number 15 directly and try to look for the last row containing data? Or do I need to convert it to a letter first?

John
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this

VBA Code:
lRow = ThisWorkbook.Worksheet("Sheet1").Cells(Rows.Count, 15).End(xlUp).Row
 
Upvote 0
Or maybe
Rich (BB code):
lRow = ThisWorkbook.Worksheets("Sheet1").Columns(15).Find("*", , xlValues, , xlByRows, xlPrevious).Row
Please note the s at the end of Worksheet
 
Upvote 0
Mark's appreciation is correct, I also forgot the "s" in worksheets ?‍♂️


Rich (BB code):
  lRow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 15).End(xlUp).Row
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0
Right… duh! You just need to get to the last cell of that particular column and then xlUp! Cheers.
Correct. That is what your original code was doing too of course, just using Range() instead of Cells()

Note that Cells() is quite flexible as you can use numbers or letters for the column. These would both do the same job
Rich (BB code):
lRow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 15).End(xlUp).Row
lRow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, "O").End(xlUp).Row
 
Upvote 0
Hey Peter, yeah, I get very confused with Range.Cells and Worksheets.Cells with how you can use cells with both Range and Worksheets. Another source of confusion is Range within Range. I doubt it's too complicated but sometimes one forgets how to spell the word "the". I suspect it'll click eventually and become self-evident. In the meanwhile, if there's a resource on all this that you can recommend, I'd certainly appreciate it.

John
 
Upvote 0
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,589
Members
449,237
Latest member
Chase S

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