A loopy solution


Q: I have attached an Excel workbook containing a list of 1,855 names in columnar format (see a partial example workbook pictured below), and I want to rearrange them into mailing label format—that is, I want all of the names and addresses in a single column.


I have successfully written a macro that rearranges a single row of data into the desired format and then moves the cursor to the next row. However, I don’t want to have to rerun the macro 1,854 times manually. How do I make this macro repeat itself automatically?

A: I believe you would be better off using Word’s Mail Merge tool to accomplish your goal, but because your question offers a good opportunity to discuss macro loops, let us proceed using your macro-based approach. I tested your macro, and it works well; you just need to add some additional code to make it repeat 1,854 times. To do this, from Excel’s View tab, select Macros, View Macros, and then select your macro in the Macro name dropdown box and click the Edit button, as pictured below.


This action will display your macro text. Next, immediately above the macro command lines, insert two lines of code: Let x = 0 and Do While x < 1855, as pictured below. In addition, immediately below the macro command lines, insert these additional two lines of code: x = x + 1 and Loop (pictured below).


When completed, select File, Save, and thereafter your macro will repeat the number of times specified in the Do While line command. You can download an example of this workbook at carltoncollins.com/loopy.xlsm.

J. Carlton Collins ( carlton@asaresearch.com ) is a technology consultant, CPE instructor, and a JofA contributing editor.

Submit a question
Do you have technology questions for this column? Or, after reading an answer, do you have a better solution? Send them to jofatech@aicpa.org. We regret being unable to individually answer all submitted questions.


Cybersecurity threats proliferating for midsize and smaller businesses

This report details how SMBs can properly protect private information from breaches, design and implement a cybersecurity policy, and create safeguards for training and education.


Test yourself on these often confused words

The spelling checker on your word processing program can do only so much to flag problems. Your best insurance is to learn the troublesome words that trip up writers and use them correctly by the standards of formal, written English.