开发者

Excel, By clicking on Cell, the Focus is moved to another cell

开发者 https://www.devze.com 2023-01-29 19:57 出处:网络
In Excel, I want to have a cell (B10) that when开发者_如何学Go clicking it, the focus will change to another cell (C12).

In Excel, I want to have a cell (B10) that when开发者_如何学Go clicking it, the focus will change to another cell (C12).

This other cell is defined in another Cell (A2).

Any Idea?

GorovDude


Use worksheet_selectChange. In essence, the code will look like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = Range("B10").Address Then
        Dim rng As Range
        Set rng = Range("A2")
        Range(rng.Value).Select
    End If
End Sub

I've hard-coded the range addresses for clarity.


This code will cause Range(A2) to be selected whenever the user clicks in column B:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Not Application.Intersect(Range("B:B"), Target) Is Nothing Then
 Range("A2").Select
 End If
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消