Autopopulate rows - linking worksheets

lisa83rtt

New Member
Joined
Feb 17, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi looking for some help with what I expect is an easy task for experienced excel users!

I have an excel sheet with a reference in the A column and a quantity in the B column. e.g.

Cell A1 - W1 Cell B1 - 2
Cell A2 - W2 Cell B2 - 4

What I'm trying to do is get another worksheet or workbook to autopopulate Column A with the references but times by the quantitys in Column B. As below;

W1
W1
W2
W2
W2
W2

I'm using Windows7.

My excel skills are restricted to basic formulas so any help would be much appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Do the following: Save the workbook as a macro-enabled file. This will change its extension to "xlsm". Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the menu at the top click 'Insert' and then click 'Module'. Copy and paste the macro into the empty code window that opens up. Change the sheet names (in red) to suit your needs. Press the F5 key to run the macro. Close the code module window to return to your sheet. There are other quicker ways to run the macro such as assigning it to a button that you would click on your sheet or assigning it to a short cut key.
Rich (BB code):
Sub lisa83rtt()
    Application.ScreenUpdating = False
    Dim LastRow As Long, x As Long, srcWS As Worksheet, desWS As Worksheet
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For x = 1 To LastRow
        desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(srcWS.Cells(x, 2)) = srcWS.Cells(x, 1)
    Next x
    desWS.Rows(1).Delete
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub My_Script()
'Modified 2/17/2020 12:35:13 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
Dim Lastrowa As Long
Lastrowa = 1
    For i = 1 To Lastrow
        Sheets(2).Cells(Lastrowa, 1).Resize(Sheets(1).Cells(i, 2).Value) = Sheets(1).Cells(i, 1).Value
        Lastrowa = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row + 1
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,914
Members
449,132
Latest member
Rosie14

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