Copy and Insert Number of rows to adjacent cell.

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182
Having a bit of trouble wrapping my head around how this would even work.

Here is the data I will need to manipulate:

ABC
1ALASKA FLY FISHING2
2JONS LOG CABINS3
3LUKAS LODGE5
4SCOTTS SALVAGE YARD
4

<tbody>
</tbody>


I am looking to have the value of B:B determine how many rows will be in lets say column D. So my output for this inquiry would be as follows:

D
1ALASKA FLY FISHING
2ALASKA FLY FISHING
3JONS LOG CABINS
4JONS LOG CABINS
5JONS LOG CABINS
6LUKAS LODGE
7LUKAS LODGE
8LUKAS LODGE
9LUKAS LODGE
10LUKAS LODGE
11SCOTTS SALVAGE YARD
12SCOTTS SALVAGE YARD
13SCOTTS SALVAGE YARD
14SCOTTS SALVAGE YARD

<tbody>
</tbody>


Appreciate you guys, thanks

J
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Give this a try:
Code:
Sub MyCopy()

    Dim myRow As Long
    Dim lastRow As Long
    Dim counter As Long
    Dim totCount As Long
    Dim myText As String
    
    Application.ScreenUpdating = False
    
'   find last row in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows in column A
    For myRow = 1 To lastRow
        myText = Cells(myRow, "A")
        counter = Cells(myRow, "B")
        Range(Cells(totCount + 1, "D"), Cells(totCount + counter, "D")) = myText
        totCount = totCount + counter
    Next myRow
        
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
You are welcome!:)
 
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,246
Members
449,304
Latest member
hagia_sofia

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