Multiply text string by number resulting in list

immikefazz

New Member
Joined
Jan 22, 2004
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello!

Using Excel 2010...

I have a list of names (text string) in a column (A) that have associated whole numbers in another column (B). What I would like to do is create a formula that multiplies the text string in cell A2 (for ex.) by the whole number in B2 and return a "list" of the text string in A2 equal to the whole number by which it is multiplied.

Here's a visual example of the results I want to achieve:

2nlbmut.jpg


Using the above example, I would like to end up with a list in column D with 159 total rows with the text contents corresponding to the whole number in column B.

Any and all help is greatly appreciated. Thank you for your time.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the board..
That seems a bit to complicated for a formula.
But here's a macro that will do it.

Code:
Sub Test()
Dim lr As Long, nm As Long, drow As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For nm = 2 To lr
    drow = Cells(Rows.Count, "D").End(xlUp).Row
    For i = 1 To Cells(nm, "B")
        Cells(drow, "D").Offset(i, 0).Value = Cells(nm, "A").Value
    Next i
Next nm
End Sub
 
Upvote 0
Solution
immikefazz ,


Sample raw data:


Excel Workbook
ABCD
1NameTransactions
2ANDY TAYLOR3
3JOHN TAYLOR11
4NICK RHODES40
5ROGER TAYLOR51
6SIMON LEBON54
7
8
9
10
11
12
13
14
15
16
17
Sheet1





After the macro (not all the rows are shown):


Excel Workbook
ABCD
1NameTransactionsResults
2ANDY TAYLOR3ANDY TAYLOR
3JOHN TAYLOR11ANDY TAYLOR
4NICK RHODES40ANDY TAYLOR
5ROGER TAYLOR51JOHN TAYLOR
6SIMON LEBON54JOHN TAYLOR
7JOHN TAYLOR
8JOHN TAYLOR
9JOHN TAYLOR
10JOHN TAYLOR
11JOHN TAYLOR
12JOHN TAYLOR
13JOHN TAYLOR
14JOHN TAYLOR
15JOHN TAYLOR
16NICK RHODES
17NICK RHODES
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ExpandList()
' hiker95, 02/06/2013
' http://www.mrexcel.com/forum/excel-questions/684025-multiply-text-string-number-resulting-list.html
Dim c As Range, nr As Long
Cells(1, 4) = "Results"
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
  nr = Range("D" & Rows.Count).End(xlUp).Offset(1).Row
  Cells(nr, 4).Resize(c.Offset(, 1).Value) = c
Next c
Columns(4).AutoFit
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the ExpandList macro.
 
Upvote 0
You are all amazing and I truly am not worthy. ;)

Each one you of provided me with the results I needed. I cannot thank you enough!
 
Upvote 0

Forum statistics

Threads
1,223,365
Messages
6,171,654
Members
452,415
Latest member
mansoorali

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top