lcol/lrow question

Offroadracer_814

New Member
Joined
Aug 7, 2015
Messages
24
To All:

Thanks for your help in advance.

Below is the VBA I have that work finding the last row in my macro when I do borders. It works great.

Dim lrow As Long
lrow = Range("A65536").End(xlUp).Row
Range("A3:U" & lrow).Select

What I am wanting to do is find a VBA that will find the last row and last column.

Thanks

Kevin
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
The code you posting only finds the last row with data in column A, and only if you have no data below row 65536 (which was the maximum number of rows in the old versions of Excel).
The new versions of Excel now allow over 1 million rows. So here is a version that will find the last row in column A, regardless of the number of rows:
Code:
lrow = Cells(Rows.Count, "A").End(xlUp).Row

If you want to find the last row/column, where you do not want to limit it to a certain row or column, one way is to use the last cell functionality. i.e.
Code:
Dim lrow as Long
Dim lcol as Long
lrow = Range("A1").SpecialCells(xlLastCell).Row
lcol = Range("A1").SpecialCells(xlLastCell).Column
 
Upvote 0
Try
Code:
Sub Offroadracer()
   Dim Lrow As Long, Lcol As Long
   Lrow = Range("A" & Rows.Count).End(xlUp).Row
   Lcol = Cells([COLOR=#ff0000]1[/COLOR], Columns.Count).End(xlToLeft).Column
   Range("A3", Cells(Lrow, Lcol)).Select
End Sub
change the value in red to a row that will always have data in the last column
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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