Finding max row containing data...

D

Dan

Hi -

Does anyone know how to quickly find the maximum row in an Excel spreadsheet
containing data? I have data between columns A-W randomly (with holes) to
some unknown row, and I need to identify which row that is. Some sheets may
have that 'maximum row' data data in column A, another it might be in column
K, etc.

Thanks very much for any help!

Dan
 
B

Biff

Hi!

One way:

Entered as an array using the key combo of CTRL,SHIFT,ENTER:

=MAX((A1:W1500<>"")*(ROW(A1:W1500)))

Use a large enough range to cover the expected result.

Biff
 
D

Dan

Thanks, Biff. Can this be used in VBA? I tried it and am not sure how it
works. What do you mean by "Entered as an array using the key combo of
CTRL,SHIFT,ENTER"?

Thanks!

Dan
 
B

Biff

Hi!
Can this be used in VBA?

That is a worksheet formula. VBA would be an entirely different technique. I
can't help with VBA.
What do you mean by "Entered as an array using the key combo of
CTRL,SHIFT,ENTER"?

Type the formula, then, instead of just hitting the ENTER key hold down the
CTRL key and the SHIFT key then hit ENTER. When done properly Excel will
place squiggly braces { } around the formula. You cannot just type the
braces in, you must use the key combination.

Biff
 
G

Gord Dibben

Dan

VBA..........

Sub LastRow()
Dim myLastRow As Long
With ActiveSheet
On Error Resume Next
myLastRow = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByRows).Row
End With
MsgBox "last row is " & myLastRow
End Sub

Formula...............

Biff's formula will be entered in a cell not in the range A1:W1500

Copy or type it into a cell then CTRL + SHIFT and hit ENTER.

This will enter it as an array formula and place curly brackets around it.

{=MAX((A1:W1500<>"")*(ROW(A1:W1500)))}


Gord Dibben Excel MVP
 
Top