答:右键工作表名,点击"查看代码",复制如下代码。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Union(Target.Cells(1, 1), Range("B2:H5")).Address = Range("B2:H5").Address Then
Range("A2") = Target.Cells(1, 1)
ElseIf Union(Target.Cells(1, 1), Range("I2:I5")).Address = Range("I2:I5").Address Then
Range("A3") = Target.Cells(1, 1)
End If
End Sub
我会写这样的代码,有实际的文件更方便测试