KimberlyHeart
New Member
- Joined
- Mar 17, 2016
- Messages
- 19
I have a workbook that I've been working on to automate a lot of activity. It currently has one large worksheet which is updated monthly. The data on this main worksheet includes data from various states, which I then sort and separate into individual worksheets based upon the state (I found code from here to do that!). The problem is that I now have 40-50 new worksheets in this original workbook. For example, I have a sheet named "AK", "AL", "AR", through "WY".
I found some code, which will select all of these new sheets, and then move them to a new workbook..
However... I keep getting a Run-time Error '9' "Subscript out of range" on the SELECT statement highlighted.
Could it be that I have it looking for all 50 states/sheets, when there is only 48 sheets available? If so, how do I fix that?
Also... while creating this code, I tried recording a macro and using portions of that code to help with this. In doing so, as it appears above, I have to move these new sheets into the newly created workbook, and then RE-ACTIVATE my original workbook. The name of this workbook may change, and I'm afraid this code will not work if the name of the "Original" changes. How do I avoid that?
Thanks!
I found some code, which will select all of these new sheets, and then move them to a new workbook..
Code:
' Move new sheets to new separate workbook
Workbooks.Add
Windows("Original.xlsm").Activate
[highlight]Sheets(Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "IA", "ID", _
"IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", _
"NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", _
"SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY")).Select[/highlight]
Sheets("AK").Activate
Sheets(Array("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "IA", "ID", _
"IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", _
"NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", _
"SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY")).Move Before:=Workbooks("Book1").Sheets(1)
Windows("Original.xlsm").Activate
However... I keep getting a Run-time Error '9' "Subscript out of range" on the SELECT statement highlighted.
Could it be that I have it looking for all 50 states/sheets, when there is only 48 sheets available? If so, how do I fix that?
Also... while creating this code, I tried recording a macro and using portions of that code to help with this. In doing so, as it appears above, I have to move these new sheets into the newly created workbook, and then RE-ACTIVATE my original workbook. The name of this workbook may change, and I'm afraid this code will not work if the name of the "Original" changes. How do I avoid that?
Thanks!