如何使用 VBA 将值(例如 LT0123)从单元格 A1 复制到单元格 A2



简而言之,我想创建一个宏并将其分配给一个形状,以便在每次单击时将相同的信息填充到每个新/空行中。

例如:A1 有"LT0123xx",当我按下按钮时,我希望它将"LT0123xx"复制到 A2 中,然后下次单击到 A3 中,依此类推。然后,我手动将A1字段更改为我需要的字段。

@BigBen - 感谢您为我指出正确的方向:)我已经找到了我需要的东西。这真的很难,因为我一生中从未做过任何编码,而且只做了 5 小时的 VBA 在线学习!谢谢,脚本如下,适合任何可能需要它的人:

Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.FormulaR1C1 = "PCxxx"
'this is inputting data into the last row with no data in the table in column A
Range("D" & Rows.Count).End(xlUp).Offset(0).Select
ActiveCell.FormulaR1C1 = "Userxxx"
'this is inputting data into the last row with no data in the table in column D
Range("F" & Rows.Count).End(xlUp).Offset(0).Select
ActiveCell.FormulaR1C1 = "ServiceCodexxx"
'this is inputting data into the last row with no data in the table in column F
Sub CopyToLastCell()
Dim xValue As Variant
    xValue = Range("A1")
    Cells(Rows.Count, "A").End(xlUp).Offset(1) = xValue
End Sub

相关内容

最新更新