View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] meh2030@gmail.com is offline
external usenet poster
 
Posts: 135
Default Deleting Sheets via Macro

On May 5, 3:09*pm, RLN wrote:
Matt,
Your solution for the sheet deletion worked very nicely here, thank
you very much!

One more thing I am trying to do:
I have a sheet that was created in Excel 2007 that we get from an
outside 3rd party. *It has approx 257k rows in it, give or take 10-30k
from month to month.
The data is on "Sheet1". *When we receive this file, "Sheet1" is the
only tab.
I am trying to write a routine that dynamically calculates the total
rows, then divides that by 65000 to get the number of sheets and then
copies and pastes blocks of rows in 65000 increments to all of the
smaller "sub-sheets" dynamically created, then deletes the larger
"sheet1" tab, then saves the file in Excel 2003 format.

I tried line #2 unsuccessfully using "longs" as variables.
lngBeginRange was equal to 1, while lngEndRange was equal to 65000 for
the first iteration of the loop.
Using line 1 with literals didn't seem to work either.
These seven lines of code are part of a loop that cycles through x
number of iterations. *(where x=total number of sub sheets that will
contain 65k rows each from the main sheet)

1. *Rows("1:65000").Select * 'select rows from main sheet
2. *' Rows(lngBeginRange & ":" & lngEndRange).Select
Selection.Copy
Sheets("NEWTESTSheet" & intLooper).Select *'give this sheet focus for
the paste coming up...
Range("A1").Select *'place the cursor in the first cell of the new
sheet....
ActiveSheet.Paste *'paste the rows...
DoEvents *'make sure all prior lines of code are run before saving the
file....

Since Line 1 and 2 do not work, I'm a bit stumped, wondering if there
is a better way.


RLN,

Dave gave you some good code to use. Simply repost if you are still
having issues.

Best,

Matt