一个非常基本的问题,但似乎无法解决。我正在尝试从“原始”单元格中获取数据,以复制到第二张工作表“技能摘要”上列表的下一个 empty 行中名为“ destination”的单元格中。提前致谢。
Sub btnS()
Dim b As Object
Dim r As Long, c As Long
Dim dest As Range, origin As Range
Dim i As Long
Dim lastrow As Long
With Worksheets("Form")
Set b = .Buttons(Application.Caller) 'references button
With b.TopLeftCell 'returns row and col of button pushed
r = .row
c = .Column + 5
End With
Set origin = .Cells(r, c)
End With
这是无效的部分
With Worksheets("Skill Summary")
lastrow = .Cells(.Rows.Count, "B").End(xlUp).row + 1
Set dest = .Cells(lastrow, 2)
End With
dest.Value = origin.Value
End Sub
答案 0 :(得分:0)
嗨,您可以使用这种代码。
因为我个人认为“ =”不适用于复制数据。
Sub btnS()
Dim b As Object
Dim r As Long, c As Long
Dim dest As Range, origin As Range
Dim i As Long
Dim lastrow As Long
ThisWorkbook.Sheets("Sheet1").Range("a1:a5").Copy
r = Cells(Rows.Count, "a").End(xlUp).Row + 1
ThisWorkbook.Sheets("Sheet2").Range("a" & Cells(Rows.Count, "a").End(xlUp).Row + 1).PasteSpecial xlPasteAll
End Sub
答案 1 :(得分:0)
避免复制和粘贴以减少内存使用并提高VBA性能
Set b = .Buttons(Application.Caller) 'references button
With b.TopLeftCell 'returns row and col of button pushed
r = .row
c = .Column
End With
Set rng2 = Sheets("Skill Summary").Cells(Rows.Count, "A").End(xlUp)
Sheets("Skill Summary").Range("A" & rng2.Row + 1 & ":A" & rng2.Row + 5).Value = Sheets("Form").Range(Cells(r, c), Cells(r, c+5)).Value