Do Loops

There are several variations of the Do loop. The most basic loop is great for doing a bunch of some mundane task. I once had someone send me a list of addresses going down a column, as shown in Figure 5.12.

I needed to rearrange these addresses into a database with name in Column B, street in Column C, city and state in Column D. By setting Relative Recording (see Chapter 1, "Unleash the Power of Excel with VBA!") and using a hot key of Ctrl+A, I recorded this little bit of useful code. The code is designed to copy one single address into database format. It also navigates the cell pointer to the name of the next address in the list. This allowed me to sit at my desk, and each time that I hit Ctrl+A, it would reformat one address for me:

Figure 5.12

Someone sent addresses typed in this format, but it is more useful to have them in a database format so they can later be used in a mail merge.

0 0

Post a comment