Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

Go to the Max

Sub GoToMax()     Dim WorkRange As Range     If TypeName(Selection) <> "Range" Then Exit Sub     If Selection.Count = 1 Then         Set WorkRange = Cells     Else         Set WorkRange = Selection     End If     MaxVal = Application.Max(WorkRange)          On Error Resume Next     WorkRange.Find(What:=MaxVal, _         After:=WorkRange.Range("A1"), _         LookIn:=xlValues, _         LookAt:=xlPart, _         SearchOrder:=xlByRows, _         SearchDirection:=xlNext, MatchCase:=False _         ).Select     If Err <> 0 Then MsgBox "Max value was not found: " _      & MaxVal End Sub