Try the below code...
You have to select the Data range and Allocation Range Manually. Made it user defined range so than you can select your desired range on which the macro needs to be performed.
Sub ArrangeData()
Dim rData As Range, rAllocation As Range, rPaste As Range
Dim lRw As Long, lCopy As Long, lStart As Long
On Error Resume Next
Set rData = Application.InputBox("Select The DATA RAMGE", "Input DATA RANGE Required", , , , , , 8)
If rData Is Nothing Then GoTo InValidRange
Set rAllocation = Application.InputBox("Select The ALLOCATION RANGE" _
& vbCrLf & vbCrLf & vbCrLf & "******EXCLUDING HEADER******", _
"ALLOCATION RANGE Required" & vbCrLf & vbCrLf, , , , , , 8)
If rAllocation Is Nothing Then GoTo InValidRange
On Error GoTo 0
Application.ScreenUpdating = False
Sheets("Output").Select
For i = 1 To rAllocation.Rows.Count
Set rPaste = Cells(Rows.Count, "A").End(xlUp)
If rPaste.Row <> 1 Then Set rPaste = Cells(Rows.Count, "A").End(xlUp).Offset(2)
If i = 1 Then lStart = rData.Row
lCopy = rAllocation.Columns(3).Cells(i).Value
rData.Rows(lStart).Resize(lCopy).Copy
With rPaste
.PasteSpecial xlPasteAll
.Offset(, 5).Resize(lCopy).Value = rAllocation.Columns(2).Cells(i).Value
End With
lStart = lStart + lCopy
Next i
Range("A:H").Columns.AutoFit
Application.ScreenUpdating = True
Exit Sub
InValidRange:
MsgBox "Invalid Input Selection Made/Provided", vbCritical, "Task Failed, Run It Again"
End Sub
Bookmarks