Macro to populate certain cells of information per row from one worksheet to another worksheet in the same workbook based on a certain criteria.

FOMOF

New Member
Joined
Oct 22, 2015
Messages
2
I am trying to create a macro that populates a new worksheet based off of a master worksheet. The data being populated is non-contiguous in the same row and only populates if a particular cell in that row is populated with "Y" as data. (Example below).

Worksheet 1 (Master)
IDPRIORITYTEAM NAMEDESCRIPTIONTEAM LOCATIONSTART DATE
1TEAM APRIMARYLONDON9.10.15
2YTEAM BSECONDARYSINGAPORE10.11.15

<tbody>
</tbody>

If column B "Priority" is populated with a "Y" then populated worksheet 2 with the following data from worksheet 1

Worksheet 2 (New) After running Macro

IDTeam NameTEAM LOCATIONSTART DATE
2TEAM BSINGAPORE10.11.15

<tbody>
</tbody>

*Note that Team one does not populate because column B is not populated with a "Y" and the description column from worksheet 1 does not get get pulled in to worksheet 2. Does anyone have a recommendation for this combination of requirements?

Thank you

FOMOF
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I would do something like this:

Code:
Sub Transplant()
Dim i As Integer
Dim k As Integer
k = 2
    Sheets("New").Cells.Clear
    Sheets("Master").Rows(1).Copy Destination:=Sheets("New").Rows(1)

    For i = 1 To Sheets("Master").Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
        If Sheets("Master").Cells(i + 1, 2).Value = "Y" Then
            Sheets("Master").Rows(i + 1).Copy Destination:=Sheets("New").Rows(k)
            k = k + 1
        End If
    Next i
Application.CutCopyMode = False
Range("A1").Select
End Sub
 
Upvote 0
Thank you, Learning To Excel, this is really close to perfect. What code would I need amend to have the data on the new worksheet begin populating on row 12 column 2 instead of A2? Also, I need to be able to select specific cells in the rows versus bringing the whole row in to the new spreadsheet ex. instead of all the data in row B12:H12, I need to be able to pick B12, E12, G12:K12, and U12:V12. It will be the same column letters for every row, just not ALL the column letters.

Thanks!
 
Upvote 0
You could use something like this:

Code:
Sub Transplant()
Dim i As Integer
Dim k As Integer
k = 12

    For i = 2 To Sheets("Master").Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
        If Sheets("Master").Cells(i, 2).Value = "Y" Then
            Sheets("Master").Range("B" & i).Copy Destination:=Sheets("New").Range("B" & k)
            Sheets("Master").Range("E" & i).Copy Destination:=Sheets("New").Range("E" & k)
            Sheets("Master").Range("G" & i & ":K" & i).Copy Destination:=Sheets("New").Range("G" & k & ":K" & k)
            Sheets("Master").Range("U" & i & ":V" & i).Copy Destination:=Sheets("New").Range("U" & k & ":V" & k)
            k = k + 1
        End If
    Next i
Range("A1").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,660
Members
449,462
Latest member
Chislobog

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