我想要复制并粘贴到工作表中的大量信息。我只想要特定的列。但是在运行此代码时,它会在此部分给出此错误.Range(MyCopyRange).Copy。我刚刚修改了我从网站上获得的代码。
Private Sub Worksheet_Activate()
Dim LR As Long, MyCopyRange As Variant, MyPasteRange As Variant, X As Long
Me.UsedRange.Offset(17).ClearContents
With Sheets("CrystalReportViewer")
.AutoFilterMode = False
LR = .Range("A" & .Rows.Count).End(xlUp).Row
MyCopyRange = Array("R1:R" & LR, "S1:S" & LR, "T1:T" & LR, "U1:U" & LR, "V1:V" & LR, "W1:W" & LR, "X1:X" & LR) 'Put ranges in an array
MyPasteRange = Array("A2", "B2", "C2", "D2", "E2")
If LR > 1 Then
For X = LBound(MyCopyRange) To UBound(MyCopyRange) 'Loop the array copying and pasting based on element in the array
.Range(MyCopyRange).Copy
Sheets("Master_File").Range(MyPasteRange).PasteSpecial xlPasteValues
Next
End If
.AutoFilterMode = False
End With
End Sub