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:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]ALASKA FLY FISHING[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]JONS LOG CABINS[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]LUKAS LODGE[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]SCOTTS SALVAGE YARD
[/TD]
[TD="align: center"]4[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


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:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]ALASKA FLY FISHING[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]ALASKA FLY FISHING[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]JONS LOG CABINS[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]JONS LOG CABINS[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]JONS LOG CABINS[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]LUKAS LODGE[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]LUKAS LODGE[/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD="align: center"]LUKAS LODGE[/TD]
[/TR]
[TR]
[TD="align: center"]9[/TD]
[TD="align: center"]LUKAS LODGE[/TD]
[/TR]
[TR]
[TD="align: center"]10[/TD]
[TD="align: center"]LUKAS LODGE[/TD]
[/TR]
[TR]
[TD="align: center"]11[/TD]
[TD="align: center"]SCOTTS SALVAGE YARD[/TD]
[/TR]
[TR]
[TD="align: center"]12[/TD]
[TD="align: center"]SCOTTS SALVAGE YARD[/TD]
[/TR]
[TR]
[TD="align: center"]13[/TD]
[TD="align: center"]SCOTTS SALVAGE YARD[/TD]
[/TR]
[TR]
[TD="align: center"]14[/TD]
[TD="align: center"]SCOTTS SALVAGE YARD[/TD]
[/TR]
</tbody>[/TABLE]


Appreciate you guys, thanks

J
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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