Moving the pointer to the cell containing the greatest value : Cell « Excel « VBA / Excel / Access / Word






Moving the pointer to the cell containing the greatest value

 
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

 








Related examples in the same category

1.Is a cell empty
2.Get the last cell
3.Magic Squares
4.Nest If statement in Do Loop While with comparison operators
5.Nest If statement in Do Loop Until for cells
6.Is active cell empty
7.Transposing is taking a rectangular block of data and rotating it so that columns become rows and vice versa.
8.Uses nested For/Next loops to count the total number of cells used in all open worksheets:
9.Selects cell G4
10.A better way to write to a range:Filling a range
11.Use arrays to fill ranges faster