Need some help finding the max value in a worksheet,
I tried with range:
Dim maxNumber As Double
maxNumber = Application.WorksheetFunction.Max(Range("A1:B5"))
Except I don’t want it to stop at B5, I want it to go through the whole Worksheet.
So I found that “XFD1048576” symbolizes the last cell of a worksheet:
Dim maxNumber As Double
maxNumber = Application.WorksheetFunction.Max(Range("A1:XFD1048576"))
Just wondering now if there’s a more elegant solution, anything to replace “XFD1048576”, or simply writing better code.
Why not use the “UsedRange” property?
Your code example would then become something like:
You can also use the Cells property –
ActiveWorkbook.Worksheets("Sheet1").Cellsto search every cell, even if it’s empty. For this reason, I’d prefer to use UsedRange.