用VBA写代码即可实现。
详细步骤如下:
1.Alt+F11,打开VBA编辑界面,双击左侧Microsoft Excel对象下的“Sheet1”,确保程序是在sheet1中执行
2.点击下图“通用”右侧的下拉箭头,选择worksheet
3.此时,代码编辑区,自动出现两串代码,如下图所示:
4.补充写上一句代码“Range("h1")=Target.text"
5.关闭VBA界面,返回Sheet1,点击任意单元格,就看到H1的值就等于点击单元格的值
可以 用 VBA Selecte change 事件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set isect = Application.Intersect(Target, Range("B7:G10"))
If Not (isect Is Nothing) Then [g5] = Target
End Sub
在G5单元格输入=INDIRECT(CELL("address")),然后点击内容单元格的时候只需要双击,然后在其他地方随意再点一下就可以了。
将下列代码粘贴到宏代码区中。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 5 And Target.Column = 7 Then Exit Sub
If Target.Row >= 7 And Target.Row <= 10 And Target.Column >= 2 And Target.Column <= 7 Then
Range("G5") = Target.Value
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row >= 2 And Target.Column <= 5 Then
r = Range("G" & Rows.Count).End(xlUp).Row
If r = 1 Then Exit Sub
If Target.Column = 1 Then Cells(r, "h") = Target.Value
If Target.Column = 2 Then Cells(r, "h") = Target.Value
If Target.Column = 3 Then Cells(r, "i") = Target.Value
If Target.Column = 4 Then Cells(r, "j") = Target.Value
If Target.Column = 5 Then Cells(r, "k") = Target.Value
End If
End Sub