我的数据中的范围应该正确,因为它们适用于复制,但是我只是想获取sheets(2)
至sheets(1)
的指定范围内的值
Private Sub insertData(RowStartData1 As Long, RowNum1 As Long)
' RowStartData1 is where the row the data starts on.
' RowNum1 is the row num - 1 where data should be inserted
Dim ColNum As Integer
RowNum1 = RowNum1 + 1
' adds one to row num so that insertion happens at right place
For ColNum = 2 To 9
Sheets(1).Range(.Cells(RowNum1, ColNum), .Cells(RowNum1 + 5, ColNum)).Value =
Sheets(2).Range(.Cells(RowStartData1, 4), .Cells(RowStartData1 + 5, 4)).Value
RowStartData1 = RowStartData1 + 6
Next ColNum
End Sub
答案 0 :(得分:4)
您遇到编译错误。您需要显式或在With
块中限定With ActiveSheet ' ## Modify as needed
' adds one to row num so that insertion happens at right place
For ColNum = 2 To 9
Sheets(1).Range(.Cells(RowNum1, ColNum), .Cells(RowNum1 + 5, ColNum)).Value = _
Sheets(2).Range(.Cells(RowStartData1, 4), .Cells(RowStartData1 + 5, 4)).Value
RowStartData1 = RowStartData1 + 6
Next ColNum
End With
的资格,例如:
Action