View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Want to get last row that has value

you could use a formula (since you posted in the worksheet function group)

=LOOKUP(2, 1/(A1:A65535<""),ROW(A1:A65535))

assuming there will never be data in row 65536 (XL versions prior to 2007
don't accept entire columns as array arguments).

Probably easier to use VBA, which is more likely what you're after:

Sub test()
Dim lngLastRow As Long

With Worksheets("Sheet1")
If IsEmpty(.Cells(.Rows.Count, 1)) Then
lngLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Else: lngLastRow = .Rows.Count
End If
End With

MsgBox lngLastRow

End Sub


"ub" wrote:

Hi
I have formula in column 'A' from 'A1:A100'. But only approx 26 cells have
values.
I want to know the last row # for column 'A' that has value. There is no
empty row in between 2 rows.
Actually I want to setup print command in my VB code to print only the rows
that have value.
If there is another way of doing this then please advise
Thanks