Macro Error When Using Copy/Pasted Data

FrenchCelt

Board Regular
Joined
May 22, 2018
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a macro that works just fine when running on the original system generated Excel report from which I get the data. I then created a macro enabled template which requires copying all the data from the original worksheet and pasting onto the template. When I run the macro from the template, I get an error (Run-time error '9': Subscript out of range), and I get the same error if I simply copy the original data, paste onto a new worksheet, and run the original macro using the shortcut key. This leads me to think that something about copying and pasting the data is affecting the format, causing the macro to error out. Does anyone have any insight into this matter?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
That error suggest a problem with the name of a workbook or worksheet.
 
Upvote 0
That error suggest a problem with the name of a workbook or worksheet.

That makes sense. This is the part of the code that errors out:

Code:
ActiveWorkbook.Worksheets("Page1_1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Page1_1").AutoFilter.Sort.SortFields.Add Key:= _
        Range("C1:C15000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal

I guess the "Page1_1" is the problem?
 
Upvote 0
Do you have a sheet with that name in the active workbook?
 
Upvote 0
Do you have a sheet with that name in the active workbook?

That is the name of the system generated report. So I changed the name in the macro to the name of the workbook in the macro enabled template. It works correctly now. Thanks for pointing me in the right direction!
 
Upvote 0
Glad it's working & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top