How to find maximum non-blank row number without brute force method?

C

Chet

Anyone know how to get the maximum non-blank row number in a range of
columns? I am looking for an answer in a couple lines because i can
probably just do it by brute force using code like ,

for colx =1 to 5
maxrow=cells(65535,colx).end(xlendup)
if maxrow> newmax then newmax=maxrow
next colx
newmax would of course be the maximum row number in the range of
columns 1-5.

But i was looking for something maybe in an array format formula? with
one line of code.(doesn't have to be an array though)
Thanks,
Chet
 
P

Per Jessen

Hi Chet

I think that I would use same approch as you, with a little modification.

Dim MaxRow As Integer
For ColX = 1 To 5
If Range(Cells(65535, ColX)).End(xlUp).Row > MaxRow Then _
MaxRow = Range(Cells(65535, ColX)).End(xlUp).Row
Next ColX

Regards,
Per
 
M

Mike H

Hi,

Try this

Sub stantial()
Set myrange = Range("A:E")
mymax = WorksheetFunction.Max(myrange)
End Sub

If you need to you can trap for zero with an IF statement
If mymax=0 then

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top