Excel VBA Question

Soldato
Joined
11 May 2004
Posts
4,790
Location
Gloucester
For my sins I'm writing a macro in VBA, and while I've got it working exactly how I want, the performance isn't fantastic. The delay seems to be in a loop where I'm blanking the content of a load of cells, I know the starting cell and the height and width of the area I want to clear in terms of number of cells, so I was wondering if there's an easy way to convert that to a range and tell excel to just wipe the entire range?

The code I have is:
Code:
    For h = 1 To height
        For w = 1 To width
            sourcecell.Offset(h, w).Value = Empty
        Next w
    Next h

sourcecell is a Range object, height and width are integers.
 
Heh, clearing the wrong ones isn't an issue, the data is extracted from a pivot table, which is populated from an OLAP cube from project server each time it's run first anyway, so accidentally deleting it all wouldn't really matter. :)

The issue now is that clear also clears the conditional formatting, can I just set them to empty?

Edit: Yes I can:

Code:
Range(sourcecell, sourcecell.Offset(height, width)).Value = Empty

Perfect, thanks James! :D

Now back to writing stuff in a real language. :p
 
Last edited:
Back
Top Bottom