Getting to the last data row in a spreagsheet

F

Frank Kabel

Hi
one way:
dim rng as range
set rng = ActiveSheet.Cells(Rows.Count, "A").End(xlUp)
msgbox rng.value
 
J

Jonathan Blitz

Is there any way to find the last row with data in a spreadsheet from with
VB?

--
Jonathan Blitz
AnyKey Limited
Israel

"When things seem bad
Don't worry and shout
Just count up the times
Things have worked themselves out."
 
C

Chip Pearson

Jonathan,

Try something like the following. Change RowNum to the desired
row number.

Dim RowNum As Long
Dim LastColInRow As Range
RowNum = 10 ' <<< CHANGE
If Cells(RowNum, Columns.Count).Value = "" Then
Set LastColInRow = Cells(RowNum, Columns.Count).End(xlToLeft)
Else
Set LastColInRow = Cells(RowNum, Columns.Count)
End If
Debug.Print LastColInRow.Address



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
J

Jonathan Blitz

Thanks.

Now I need the same for the columns.
Need to get to the last column containing data.

--
Jonathan Blitz
AnyKey Limited
Israel

"When things seem bad
Don't worry and shout
Just count up the times
Things have worked themselves out."
 
Top