Question: In Excel, if I have a list of quantities in Column A and a list of product names in column B, how can I create a Macro to copy the product names the number of times indicated by the quantity in Column A? So in Column C, I would have the product names listed in a row the number of times that is given by the quantity. Answer: Let's take a look at an example. Download Excel spreadsheet (as demonstrated below)
|
In our spreadsheet, we have our quantities listed in Column A and our product names listed in Column B.
|
To run the macro, select Macro > Macros under the Tools menu.
|
When the Macro window appears, select the macro called CopyToColumnC and click on the Run button.
|
When the macro has completed, the above message box will appear.
|
You should now see the product name appear in Column C, the number of times based on the value in the quantity column. In this case, Mr. Clean appears 2 times, Bounty towels appears 5 times, and Tide detergent appears 1 time. You can press Alt-F11 to view the VBA code. Macro Code:The macro code looks like this:
|
Visit our busy book shop, were you can find latest books for beginners as well as advanced excel users.
Spreadsheet 123 Spreadsheet Software Development
See Spreadsheets for:
a.Hotel Management b.Personal Budget
c.Corporate Finance d.Rating Calculation e.Real Estate and Mortgage
f.Web Calc