my skills in Excel VBA come from googling and thus I've ran into an issue. I've used copy and paste and this import code without issue and without having to activate the sheet before so I am unsure why this is erroring out now. I import the data form one workbook into the Macro, and then copy certain columns into another sheet. However, the code only seems to work if the sheet "Cut Report" is active, else it gives a 1004 error (or others). Even with the sheet active, I can see it selecting the rows below the data before switching the sheet to paste.
Sub ImportCut()
' Get workbook...
Dim ws As Worksheet
Dim filter As String
Application.ScreenUpdating = False
Dim targetWorkbook As Workbook, wb As Workbook
Dim Ret As Variant
MsgBox ("Please select the Cut Report.")
Set targetWorkbook = Application.ActiveWorkbook 'The current open Workbook
' get the customer workbook
Caption = "Please Select an input file "
Ret = Application.GetOpenFilename(filter, , Caption) 'Opens dialog box to find and select file.
If Ret = False Then End 'If no file is selected, program ends.
Set wb = Workbooks.Open(Ret) 'sets selected workbook to wb.
wb.Sheets(1).UsedRange.Copy targetWorkbook.Sheets("Cut Report").Range("A1") 'copies data from selected wb to current open workbook.
wb.Close 'closes wb
End Sub
Code with Issue, I've tried with "Sheets", "Worksheets", "Workbook("Macro Sheet").Worksheets("Cut Report"). Even testing with Sheets("Cut Report").Range("AC2").Select it gives an error.
Sub CopyOverBasic()
Sheets("Cut Report").Range("AC2", Range("AC2").End(xlDown)).Copy Sheets("Customer Report").Range("A8")
Sheets("Cut Report").Range("G2", Range("G1").End(xlDown)).Copy Sheets("Customer Report").Range("B8")
Sheets("Cut Report").Range("Z2", Range("Z1").End(xlDown)).Copy Sheets("Customer Report").Range("C8")
Sheets("Cut Report").Range("I2", Range("I1").End(xlDown)).Copy Sheets("Customer Report").Range("D8")
Application.CutCopyMode = False
End Sub