我有一个带有一系列值(K3:K89)的工作簿,我想用一些公式进行转换,然后粘贴到工作簿中的某个位置。问题是我希望能够在第一行和第四行中粘贴这些值。这是我到目前为止的代码。
Sub Copy()
Range("K3:K89").Select
ActiveWindow.SmallScroll Down:=-60
Selection.Copy
Range("R3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Range("L3").Select
Sheets("Sheet2").Select
End Sub
我无法解决每四行粘贴值的问题。帮助将非常感激。
答案 0 :(得分:1)
Sub test()
Dim firstRow As Integer, lastRow As Integer, totalLines As Integer, i As Integer, k As Integer
Dim ws As Worksheet
Set ws = ActiveSheet
k = 0
firstRow = 3
lastRow = Cells(3, 11).End(xlDown).Row
' how many total values do you have?
totalLines = lastRow - firstRow + 1
'Now, loop through the range of values, pasting to Column 18 (column R), skip 3 rows and repeat
For i = 0 To totalLines
Cells(3 + k, 18).Value = Cells(3 + i, 11).Value
k = k + 4 ' add 4 to k, to skip 4 more lines
Next i
End Sub