我正在使用以下字符串将列从一个工作表复制到另一个工作表
Dim wsCore As Worksheet
Dim wsData As Worksheet
Set wsCore = Sheets("R2 Data Dump")
Set wsData = Sheets("Active")
Dim rowNumber As Integer
Dim cellFormulas As Variant
Dim cellFormulas1 As Variant
Dim counter As Integer
counter = 0
Dim currentCell As String
Dim importSheetCell As Variant
Dim importSheetOffset As Variant
Dim contractnum As Integer
Dim pt As PivotTable
Dim ws As Worksheet
Dim pc As PivotCache
Dim lastrow As Long
Set wsCore = Sheets("R2 Data Dump")
Set wsData = Sheets("Active")
Sheets("R2 Data Dump").Visible = True
Sheets("R2 Data Dump").Select
rowNumber = ActiveSheet.UsedRange.Rows.Count
With wsCore
Startrow = 3
wsCore.Columns("W").Copy Destination:=wsData.Columns("A")
wsCore.Columns("B").Copy Destination:=wsData.Columns("B")
wsCore.Columns("C").Copy Destination:=wsData.Columns("C")
wsCore.Columns("D").Copy Destination:=wsData.Columns("D")
End With.
那么做什么是从一张纸上复制特定的列并将其粘贴到目标纸的指定列上。我的问题是,操作开始将复制的单元格从源表格粘贴到目标单元格的第一行。我想知道的是如何设置行号而不是第1行。
答案 0 :(得分:1)
通常,您将转到列中的第一个空白单元格(从下往上看)。
With Intersect(wsCore.Columns("A:W"), wsCore.UsedRange)
.Columns("W").Copy Destination:=wsData.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Columns("B").Copy Destination:=wsData.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
.Columns("C").Copy Destination:=wsData.Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
.Columns("D").Copy Destination:=wsData.Cells(Rows.Count, "D").End(xlUp).Offset(1, 0)
End With
如果要指定行,请声明一个长变量并使用它。
Dim rw As Long
rw = 10
With Intersect(wsCore.Columns("A:W"), wsCore.UsedRange)
.Columns("W").Copy Destination:=wsData.Cells(rw, "A")
.Columns("B").Copy Destination:=wsData.Cells(rw, "B")
.Columns("C").Copy Destination:=wsData.Cells(rw, "C")
.Columns("D").Copy Destination:=wsData.Cells(rw, "D")
End With
我使用Intersect
来防止尝试将完整列复制到不在第一行开始的列中。完整列不适合。