Tuesday, May 26, 2009

Delete All the Charts in Excel (through VBA)

Just needed to delete a lot of charts. I'm generating some as well and all the practice charts are building up.

********************************
For i = 1 To ActiveSheet.ChartObjects.Count 'Cycle through the Charts
ActiveSheet.ChartObjects(i).Delete ' Delete each Chart
Next i 'NEXT CHART
**********************************

The bulk of the code is in this loop. Surrounding code is pretty easy

Tuesday, May 19, 2009

Escape Hard Return in VBA

It's always a pain to remember a hard return in VBA.  So I thought I'd get it documented.  There is actually more than one. I may post the differences in a future post.
---- CODE ------
vbCrLf
vbNewLine

---- END CODE  ------

Tuesday, April 28, 2009

VBA Replace Method

I've been using the Replace method a lot lately.  Wanted to get it up and front.  The first time I used it, I found someone who had re-programmed it -- so I have some useless code in one of my projects.

Instead of doing a big writeup, here are examples from

------ CODE -------
Replace("alphabet", "bet", "hydro") would return "alphahydro" 
Replace ("alphabet", "a", "e") would return "elphebet" 
Replace("alphabet", "a", "e", 2) would return "lphebet" 
Replace("alphabet", "a", "e", 1, 1) would return "elphabet"
---- END CODE