问题描述:

Is there a shortcut for moving down a column or across a row to the next cell with a different value from the current one?

网友答案:

Here is an example for moving to the right until a different value is found. Assign a shortcut key to this little macro:

Sub MoveToTheRight()
    Dim v As Variant, i As Long, j As Long
    v = ActiveCell.Value
    j = ActiveCell.Column
    k = ActiveCell.Row
    For i = j + 1 To Columns.Count
        With Cells(k, i)
        If .Value <> v Then
            .Select
            Exit Sub
        End If
        End With
    Next i
End Sub

and here is a sample for moving downwards:

Sub MoveDown()
    Dim v As Variant, i As Long, j As Long
    v = ActiveCell.Value
    j = ActiveCell.Column
    k = ActiveCell.Row
    For i = k + 1 To Rows.Count
        With Cells(i, j)
        If .Value <> v Then
            .Select
            Exit Sub
        End If
        End With
    Next i
End Sub
相关阅读:
Top