Phone (01457) 858877 or email
There are 4 types of loop in Visual Basic for Applications - this blog shows how and when to use each type of VBA loop structure.
This series of blogs is part of our Excel VBA online tutorial. We also run training courses in Excel and VBA.
There are essentially three types of loop that you can write in Visual Basic for Applications:
These are in ascending order of usefulness. If you're an experienced VBA programmer, looping over the objects in a collection is nearly always the way to go.
The rest of this blog gives examples of each type of loop, with the possible forms of syntax.
There are 4 types of loop in Visual Basic for Applications - this blog shows how and when to use each type of VBA loop structure.
This series of blogs is part of our Excel VBA online tutorial. We also run training courses in Excel and VBA.
Comments on this blog
This blog has 5 comments:
Apologies for the delay in replying (I've been on a well-earned holiday).
Not sure I understand the question ...
'fraid not. Don't think it would be anything to do with looping over cells (the subject of this blog) even if I knew one. Suspect it would have to be a messy macro involving arrays of all the possible words, with lots of SELECT CASE conditions for the exceptions.
Yeah Andy is right the application of this task is a reasonably messy bit of code. It is possible though and there are a number of examples posted online. One of which is here;
http://www.vbaexpress.com/kb/getarticle.php?kb_id=735
If you follow the instructions diligently you will get the result you are after.
Take care
Smallman
Sorry about that ...
Incidentally, I've corrected the cell reference you referred to in a previous comment - many thanks for taking the time to let me know about this.
You mention that you don't like any of the alterntaive syntaxes for the WHILE and UNTIL loops, however the structures where the condition is tested at the bottom of the loop operate with a distinct difference than those that test the condition at the top of the loop.
Specifically, if you test at the top of the loop, the loop may never execute if the condition is not satisfied, whereas if you test at the bottom of the loop the loop will always execute at least once.
The distinction is important and I've often needed to use top test or bottom test as the situation required.
Thanks