Hello all,
I'm attempting to perform a relatively straightforward procedure in VBA with a certain nuance which is complicating things, my basic task is to Move a selection of tabs from one open workbook ('all.xls') to a new workbook also open ('new.xls').
However, where this becomes complicated is the criteria upon which a tab is deemed part of said selection to be moved.
For examples sake, lets say there are two 'selections' of tabs, one called Dog and one called Cat (we'll focus on 'Dog' here...)
Each of these tabs is named as follows - Dog, Dog(1), Dog(2), Dog(3) etc etc (i.e - the naming convention generated by Excel when you try to drop lots of worksheets with the same name into one workbook).
So, I want to move all the 'Dog' tabs into the new (already open) workbook. However, sometimes the range will be from Dog to Dog(20), sometimes from Dog to Dog(11) etc - ie, there will be different numbers of tabs each month.
I tried to create an array of tabs to move in VBA, however when the number of tabs there are changes (or rather, is less than that defined in the array) then VBA clicks into debug mode as obviously it cant find the referenced tab to move. Further, if there are more 'Dog' tabs than defined in the array then some will not be moved into the new workbook.
In my head, the solution to this is to somehow get the code to search for tabs starting with 'Dog' and move them, but I have no idea how to do this.
Any ideas?
Please let me know if I can provide info, or if the above doesn't make sense.
Thanks,
Richard
I'm attempting to perform a relatively straightforward procedure in VBA with a certain nuance which is complicating things, my basic task is to Move a selection of tabs from one open workbook ('all.xls') to a new workbook also open ('new.xls').
However, where this becomes complicated is the criteria upon which a tab is deemed part of said selection to be moved.
For examples sake, lets say there are two 'selections' of tabs, one called Dog and one called Cat (we'll focus on 'Dog' here...)
Each of these tabs is named as follows - Dog, Dog(1), Dog(2), Dog(3) etc etc (i.e - the naming convention generated by Excel when you try to drop lots of worksheets with the same name into one workbook).
So, I want to move all the 'Dog' tabs into the new (already open) workbook. However, sometimes the range will be from Dog to Dog(20), sometimes from Dog to Dog(11) etc - ie, there will be different numbers of tabs each month.
I tried to create an array of tabs to move in VBA, however when the number of tabs there are changes (or rather, is less than that defined in the array) then VBA clicks into debug mode as obviously it cant find the referenced tab to move. Further, if there are more 'Dog' tabs than defined in the array then some will not be moved into the new workbook.
In my head, the solution to this is to somehow get the code to search for tabs starting with 'Dog' and move them, but I have no idea how to do this.
Any ideas?
Please let me know if I can provide info, or if the above doesn't make sense.
Thanks,
Richard