I transfer data from sheet "instru" to the sheet "data" using this code.
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
I want to achieve the same for a dynamic range. It should count the rows present in sheet "instru" and copy only that many rows to "data" sheet.
Eg I want to copy ("A1:D1") based on the count of column "A" in "instru".
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.