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 REPORT

Keeping client information safe in an age of scams and security threats

A look at the Dirty Dozen tax scams and ways to protect taxpayer information.

TAX PRACTICE CORNER

More R&D tax help

"Can I use the R&D credit?" PATH Act enhancements make the credit more attractive to a wider range of taxpayers.

QUIZ

News quiz: Tax-related data breach explained

News about a data breach that affected about 100,000 people, the IRS’s budget for the fiscal year, and the 2018 health spending account limits received attention recently. See how much you know with this short quiz.