我使用此代码将数据从工作表“ instru”传输到工作表“ data”。
Option Explicit
Sub lastrow()
Dim wsS1 As Worksheet 'Sheet1
Dim wsS2 As Worksheet 'sheet2
Dim lastrow As Long
Set wsS1 = Sheets("Instru")
Set wsS2 = Sheets("data")
With wsS1
lastrow = range("A:A" & Rows.Count).End(xlUp).Row
wsS1.range("A5:KU5" & lastrow).Copy wsS2.range("A1:KU11440" & lastrow)
End With
End Sub
我想在动态范围内达到相同的效果。它应该计算工作表“ instru”中存在的行,并且仅将那么多行复制到“数据”工作表中。
例如我想根据“ instru”中“ A”列的计数来复制(“ A1:D1”)。
答案 0 :(得分:0)
Sub lastRow()
Dim wsS1 As Worksheet 'Sheet1
Dim wsS2 As Worksheet 'sheet2
Dim lastR As Long
Set wsS1 = Sheets("Instru")
Set wsS2 = Sheets("data")
With wsS1
lastR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A5:KU" & lastR).Copy wsS2.Range("A1")
End With
End Sub