I’m running into a 1004 run-time error: copy method of worksheet class fails and I don’t know how to fix it.
My macro file contains 3 worksheets; the first 2 are named “Summary” and “By Market Report,” respectively. These worksheet names are static.
My claims file contains 3 worksheets, and I want to copy 2 Worksheets to the macro file. The file and worksheet names are dynamic. I get the claims file name through a file picker and I prompt the user for the worksheet names in a userform.
Here is my code that fails: Workbooks(txtClaimsFname).Worksheets(txtClaimsShtName).Copy After:=Workbooks(txtMacroFname).Worksheets("By Market Report"). Both files are open during the copy.
When I step through the code and hover over each variable, the contents are correct. That is, the FName variables show the correct file name and extension, and txtClaimsShtName contains the worksheet name.
So far, I’ve also tried these statements and get the same error: Workbooks(txtClaimsFname).Worksheets(ClaimsShtName).Copy After:=Workbooks(txtMacroFname).Worksheets(2) and Workbooks(txtClaimsFname).Worksheets(ClaimsShtName).Copy After:=Workbooks(txtMacroFname).Sheets(Workbooks(txtMacroFname).Worksheets.Count)
I hope you can help me and possibly provide an explanation of why it fails. Thank you
My macro file contains 3 worksheets; the first 2 are named “Summary” and “By Market Report,” respectively. These worksheet names are static.
My claims file contains 3 worksheets, and I want to copy 2 Worksheets to the macro file. The file and worksheet names are dynamic. I get the claims file name through a file picker and I prompt the user for the worksheet names in a userform.
Here is my code that fails: Workbooks(txtClaimsFname).Worksheets(txtClaimsShtName).Copy After:=Workbooks(txtMacroFname).Worksheets("By Market Report"). Both files are open during the copy.
When I step through the code and hover over each variable, the contents are correct. That is, the FName variables show the correct file name and extension, and txtClaimsShtName contains the worksheet name.
So far, I’ve also tried these statements and get the same error: Workbooks(txtClaimsFname).Worksheets(ClaimsShtName).Copy After:=Workbooks(txtMacroFname).Worksheets(2) and Workbooks(txtClaimsFname).Worksheets(ClaimsShtName).Copy After:=Workbooks(txtMacroFname).Sheets(Workbooks(txtMacroFname).Worksheets.Count)
I hope you can help me and possibly provide an explanation of why it fails. Thank you