将excel中的光标移动到具有不同内容的下一个单元格

时间:2014-11-08 16:47:18

标签: excel cursor-position

是否有一个快捷方式,可以将列向下或跨行移动到下一个单元格,其值与当前单元格的值不同?

1 个答案:

答案 0 :(得分:1)

这是向右移动直到找到不同值的示例。为此小宏指定快捷键:

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

这是一个向下移动的示例:

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