finding largest value

R

R

Using VBA I need to find the largest number in column A over all my sheets.
So say I have 5 sheets in my workbook I want to find the largest number
within all the column A's. Then just set what ever this number is to a
variable I have in my code (say intI)--this part is simple. I am new to
programming within the Excel environment so I'm not sure how to do the first
part.

Thanks
 
V

Vergel Adriano

R,

Try something like this:

Sub test()
Dim sht As Worksheet
Dim lValue As Long
Dim lLargest As Long

For Each sht In ActiveWorkbook.Worksheets
lValue = Application.WorksheetFunction.Large(sht.Range("A:A"), 1)
If lValue > lLargest Then lLargest = lValue
Next sht

MsgBox lLargest

End Sub
 
R

R

Awesome....thanks so much

Vergel Adriano said:
R,

Try something like this:

Sub test()
Dim sht As Worksheet
Dim lValue As Long
Dim lLargest As Long

For Each sht In ActiveWorkbook.Worksheets
lValue = Application.WorksheetFunction.Large(sht.Range("A:A"), 1)
If lValue > lLargest Then lLargest = lValue
Next sht

MsgBox lLargest

End Sub
 

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