A loopy solution

BY J. CARLTON COLLINS, CPA

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.

SPONSORED QUIZ

How well do you know small business?

There are over 30 million small businesses in the U.S., and many of them are optimistic in their outlook. Are you familiar with the obstacles and opportunities they are facing? Test your small business acumen with this quiz sponsored by Chase Ink®.

SPONSORED REPORT

In focus: Payroll

Providing payroll services that comply with ever-changing regulations and meet evolving employee and employer demands is no easy task. Paychex's Tom Hammond discusses common payroll considerations for CPA firms.