我目前有一个循环运行,它选择一个范围,复制,然后粘贴所需列中的值:
Set wks6 = wkb.Sheets.Add
With wks6
Dim rstCP As Recordset
Dim firstCP As Boolean
Dim previousPot As Integer
Set rstCP = CurrentDb.OpenRecordset("FUT_CR_Capacity_Count")
firstCP = False
previousPot = 0
Do While Not rstCP.EOF
If firstCP = False Then
.Range("N3", "AA3").Copy
.Range("AB" & rstCP![COuntWC] + 3).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
previousPot = previousPot + rstCP![COuntWC] + 3
firstCP = True
Else
.Range("N" & previousPot + 1 & ", AA" & previousPot + 1 & "").Copy
Debug.Print "N" & previousPot + 1 & ",AA" & previousPot + 1 & ""
.Range("AB" & rstCP![COuntWC] + previousPot + 1).PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Debug.Print "AB" & rstCP![COuntWC] + previousPot + 1
previousPot = previousPot + rstCP![COuntWC] + 1
End If
rstCP.MoveNext
Loop
End With
所以循环的第一部分(If firstCP = False Then
)运行得很好;它将范围N3复制到AA3,进一步自动粘贴AA13到AO13范围内的值。但是当循环继续所有其他增量(if语句的else部分)时,它会部分地粘贴AA15到AB15列的值。
注意:我已尝试在粘贴中指定范围:
.Range(AA#,AO#).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
......但这不起作用。