VBA to copy number of rows to specific sheets based on a few cell values

stupurd

New Member
Joined
Jan 18, 2016
Messages
7
Hello.

I've search this site to try and find the answer but I what I require is a bit more specific than simply copying a list based on a quantity. I'll explain more:

I have a sheet and in this sheet lists tasks in column A, whether they are required or not in column B, The quantity in column C and finally a location (sheet) these tasks need to be copied to in column D. Hopefully, this is a bit clearer:

TaskRequiredQtyLocation
Task 1Y4Project Lead
Task 2Y4
Project Lead
Task 3N3Mechanical
Task 4Y2Project Lead
Task 5Y2Project Lead
Task 6Y1Project Lead
Task 7Y1Project Lead

<tbody>
</tbody>

I'd like the task (Cell A2), if it is required (Cell B2), to be copied the numbers of times in the Qty column (B3) into the sheet shown in the Location column (Cell B4)

The cell within each sheet that this data is to be copied into will start at Cell D3.

I hope that makes sense.

Regards

Stuart
****** id="cke_pastebin" style="position: absolute; top: 166px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
Project Lead

<tbody>
</tbody>
</body>
 
You're welcome :) Not much difference in the two suggested scripts, just different approaches for you to consider and adjust as need be!
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Glad you have things working for you.
I do not understand why you had to change column numbers
And I do not understand:
(The format of which is a little convoluted, a simple table was created to ask for help).
 
Upvote 0
@my answer is this - what about if I want to copy the entire row?

Try this:
Run script from Master sheet

Code:
Sub Test()
'Modified 5/1/2018 8:10 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        If Cells(i, "B").Value = "Y" Then
            Lastrowa = Sheets(Cells(i, "D").Value).Cells(Rows.Count, "D").End(xlUp).Row + 1
            If Lastrowa < 5 Then Lastrowa = 5
            Cells(i, "A").Copy Sheets(Cells(i, "D").Value).Cells(Lastrowa, "D").Resize(Cells(i, 3).Value)
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Well what was wrong with my original answer?
You said you had to modify the columns but did not explain what was wrong.
 
Upvote 0
I thought you asked a second question about copying entire row but that question disappeared.
 
Upvote 0
I thought you asked a second question about copying entire row but that question disappeared.
You're quite the OP did.
I removed the post thinking (for some reason) that it was duplicated!
I've re-instated it, along with your reply.
Apologies for that. Must have had a "senior" moment
 
Upvote 0
@Fluff, think the confusion is a different poster (@p9j213) asked about the rows compared to the original poster (@stupurd) who asked about values in column A
 
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,510
Members
449,166
Latest member
hokjock

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