finding last row

ricksimm

Board Regular
Joined
Apr 28, 2005
Messages
188
i use the following to find the last row in column A.
Code:
        lbrowCNT = Range("A1", Range("A" & Rows.Count).End(xlUp)).Rows.Count
If I have columns A thru X and each column can have a different number of rows in use, can the above statement be modified to find the row count for the longest column? Or do I have to look at each column separately? Thanks.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
try

Code:
lr = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Row - 1

replace activesheet with an appropriate sheet name.
 

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
This is better for just that case.


Code:
Dim LstRw As Long, c As Range
Set c = Cells.Find(What:="*", After:=Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If c Is Nothing Then
    LstRw = 1
Else
    LstRw = c.Row
End If

Hope this helps!
 

Forum statistics

Threads
1,181,730
Messages
5,931,718
Members
436,800
Latest member
abowalid98

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
Top