Excel, By clicking on Cell, the Focus is moved to another cell
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
精彩评论