EXCEL vba选择指定区域,A1的值等于指定区域中选中单元格的值,该如何实现?

2024-10-31 19:23:20
推荐回答(4个)
回答1:

工作表事件,代码如下:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Count = 1 And Target.Row <= 9 And Target.Column = 9 Then

        Range("a1").Value = Target.Value

    End If

End Sub

对照图:

回答2:

Range("a1") = ActiveCell

回答3:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Range("i1:i9"), Target) Is Nothing Then
Range("a1") = ""
Else
Range("a1") = Target
End If

End Sub

回答4:

Sub a()
Dim i
For i = 1 To 9

If ActiveCell = Range("I" & i) Then

Range("a1") = Range("I" & i).Value

End If

Next i

End Sub