Deleting Sheets via Macro
Dave,
This example worked very nicely...thank you!
I do have a couple of questions on a few lines of code you provided,
not because I doubt your expertise here, but only because I want to
understand a little more what Excel is doing.
Set DestCell = Worksheets.Add(after:=Sheets(Sheets.Count)).Range( "A1")<<
As I stepped through the code with the debugger, your line added the
new blank sheet to the workbook and worked fine.
However, when I recorded a macro to do the same thing, Excel gave me
these three lines of code:
-Sheets.Add
-Sheets("Sheet11").Select
-Sheets("Sheet11").Name = "NEWSHEET10" 'renamed the sheet
I'm just wondering why Excel wouldn't provide better code where you
can set properties ("after:=") on the same line. I haven't written
too many macros inside of Excel and it would have been good for Excel
to provide a line such as what you gave here in your example. (It's
Microsoft...I know, and that is why we have these newsgroups.)
I did not know that this:
-Sheets("Sheet11").Name = "NEWSHEET10" 'renamed the sheet
is the same as this....
-DestCell.Parent.Name = "Split_" & Format(pCtr, "000")
....only in your example I like how you used the format function here.
I was not aware of the "parent.Name" property.
Finally....
.Rows(lCtr).Resize(myStep).Copy Destination:=DestCell
I didn't realize this would do a copy/paste in the same line of code.
All of my macros I tried to record did them in two steps and they did
not work very well when performing it in a bulk dump fashion to
multiple sheets.
Again Dave, thank you for your example, it works very nicely, and I
appreciate your assistance here.
|