Help with getting rid of unused cells or ranges

  • Thread starter Thread starter TBA
  • Start date Start date
T

TBA

Windows 2k Pro
Excel 2000

I have a macro that I wrote that compares two lists of data. One of the
options allows the user to run the macro again (as often as they like). The
lists that the user will be comparing can be of any size, from 100 rows of
values to 40,000 or more rows of values (up to the magical 65,536 of
course). I also gave the user the option to save the Results worksheet as a
CSV file. One of the things I noticed during testing was that the saved CSV
files were larger than I had thought they would be. I discovered that if on
the previous macro run that the lists were larger than the lists on the
current run, then those rows were being saved by the Save procedure, as
evidenced by the many many rows of commas at the end of the actual saved
data in the CSV file. I believe this is an issue of "used" Ranges, no?

I have incorporated some format procedures in my code, but unfortunately I
didn't allow for the above mentioned possibility.

Is it possible to incorporate a procedure within my Save procedure that will
re-set the "used" Range on my Results worksheet?

The way I see it I can either copy and paste only the range containing
results and save that, or I can delete all the unnecessary rows from the
Results worksheet and copy, paste and save that worksheet. Am I on the
right track?

If I go with the first option, then I have to find the last row containing a
non-blank value, which, for the sake of argument, could be in one of five
non-contiguous columns. I would then have to be able to select the range
from A1 to K??, with ?? being the row number which contains the last
non-blank value.

Any help in the right direction would be greatly appreciated.

-gk-
 
The statement:

ActiveSheet.UsedRange

by itself will reset the active area to the last cell with something in it
(contents, formatting, comment). Maybe using that after a ClearContents
will help.
 
Back
Top