0
我正在使用此宏將數據從工作簿'x'中的3列複製到工作簿'y',而不復制隱藏行。excel vba宏:將列信息複製到另一個工作簿
Sub GetDataDemo()
Const FileName As String = "EHS.xlsx"
Const SheetName As String = "PO"
FilePath = "C:\Users\DD\Desktop\"
Dim wb As Workbook
Dim this As Worksheet
Dim i As Long, ii As Long
Application.ScreenUpdating = False
If IsEmpty(Dir(FilePath & FileName)) Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Else
Set this = ActiveSheet
Set wb = Workbooks.Open(FilePath & FileName)
With wb.Worksheets(SheetName).Range("Y:AA")
ii = 3
For i = 3 To 500
If Not .Rows(i).Hidden Then
.Cells(i).Copy
this.Range("P:R").Cells(ii).Paste
ii = ii + 1
End If
Next i
End With
End If
ActiveWindow.ScreenUpdating = True
End Sub
我不斷收到自動化錯誤(錯誤440)附近的行:
this.Range("P:R").Cells(ii).Paste
感謝您的幫助提前!
不應該是'.SpecialCells(xlcelltypevisible).Copy this.Range(「P3」)'? – SJR
@SJR - 這不是做同樣的事情嗎? – BruceWayne
@BruceWayne - 'Paste'不是'Range'對象的方法。 (它是'Worksheet.Paste'或'Range.PasteSpecial'。) – YowE3K