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.


Year-end tax planning and what’s new for 2016

Practitioners need to consider several tax planning opportunities to review with their clients before the end of the year. This report offers strategies for individuals and businesses, as well as recent federal tax law changes affecting this year’s tax returns.


News quiz: Retirement planning, tax practice, and fraud risk

Recent reports focused on a survey that gauges the worries about retirement among CPA financial planners’ clients, a suit that affects tax practitioners, and a guide that offers advice on fraud risk. See how much you know with this short quiz.


Bolster your data defenses

As you weather the dog days of summer, it’s a good time to make sure your cybersecurity structure can stand up to the heat of external and internal threats. Here are six steps to help shore up your systems.