您好我正在尝试编写一个工具,以便当我双击列a上的任何单元格时,它将填充在b列中。列a将包含许多不同行的不同字符串,我希望能够简单地双击任何单元格以在列b上填充它。
即;我会点击单元格a1,a5,a8,a111,这些单击的4个单元格将出现在列b1,b2,b3,b4
我知道我错过了一个循环,但我似乎无法弄清楚我想把它放在哪里
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
x = 1
sel = Target.Value
Cells(x, 2).Value = sel
x = x + 1
Cancel = False
End Sub
先谢谢
答案 0 :(得分:0)
你真的不需要循环:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
Dim rgOut as Range
If Target.Column = 1 then
Set rgOut = Cells(Rows.Count, "B").End(xlUp)
if len(rgOut.formula) <> 0 then set rgOut = rgOut.Offset(1)
rgOut.Value = Target.Value
End If
End Sub