Formula or macros to pull data into new sheet based on "yes/no" criterion

daniellelp

New Member
Joined
Nov 9, 2013
Messages
4
Hi all,

Thank you in advance for any guidance you may provide. I have a spreadsheet with these headers and these fake data:
Unique IDOpen House DateAttended?lastNamefirstNameemailaddress1address2citystatecountry
16/1/13yesmorganpierspm@xx.com101st streetNew YorkNYUSA
26/1/13yeswaltersbarbarabw@xx.comeast streetPhiladelphiaPA
36/1/13nostewartjonjs@xx.comwest stapt. 5ArlingtonVA
46/1/13noo'brienconancob@xx.comnorth stBirminghamALUSA
56/1/13yesbeckglenngb@xx.com1st aveNew OrleansLA
66/1/13yesdegeneresellened@xx.comelm street9BSt. LouisMO
76/1/13nocolbertstephensc@xx.combroadwayapt. 2cHonoluluHIUnited States
86/1/13yeswinfreyoprahow@xx.commaple laneSaddle RiverNJ
96/1/13nohandlerchelseach@xx.comcolumbus circleApt 105San DiegoCA
106/1/13nofergusoncraigcf@xx.comlove laneDetroitMIUS

<tbody>
</tbody>

The data get updated every couple weeks and are assigned a new, sequential, unique identifier (the spreadsheet has unique IDs listed 1-900, the new data is copy-pasted at the bottom of the existing data; not ideal, but the way the boss wants it). This unique ID is used in other vlookup formulas in the same file.

My question is: I would like to automatically pull the firstName, lastName, address1, address2, city, state, and country into another sheet ("Mailings") in the same workbook IF the individual has a "yes" in the "Attended?" column. IF the individual has a "no" in the "Attended?" column, I would like to pull that person's firstName, lastName, and email into another sheet in the same workbook ("Email_blast").

The catch is that I want only information for "yes" folks in the Mailings sheet, and only information for "no" folks in the Email_blast sheet, with no empty spaces or empty rows of formulas. I would also like this to update every time I add in new data. I have tried, in the "Mailings" sheet, an =IF, which looks for a yes in the "Attended?" column, and if found, pulls in the needed information. If not found, it pulls in "" (blank cells). The problem is that there are now a ton of seemingly blank cells. My ideal final "Mailings" sheet would look like this (separate sheet in same workbook):

morganpiers101st streetNew YorkNYUSA
waltersbarbaraeast streetPhiladelphiaPA
beckglenn1st aveNew OrleansLA
degeneresellenelm street9BSt. LouisMO
winfreyoprahmaple laneSaddle RiverNJ

<tbody>
</tbody>

And "Email blast:"

stewartjonjs@xx.com
o'brienconancob@xx.com
colbertstephensc@xx.com
handlerchelseach@xx.com
fergusoncraigcf@xx.com

<tbody>
</tbody>

I hope this is clear. If anyone has thoughts, or if I'm missing something super obvious, please do let me know. Thank you so much!!!
Danielle
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Danielle,

Give this a try, copy and paste in the worksheet module of the sheet with the data on it.
Code assumes there are headers on each sheets "Mailings" & "Email_blast".

Regards,
Howard

Code:
Option Explicit

Sub ColCYesNo()
'// w/much help from Mickg @ this forum

Dim ShtTargetYs As Worksheet
Dim ShtTargetNo As Worksheet
Set ShtTargetYs = Sheets("Mailings")
Set ShtTargetNo = Sheets("Email_blast")
Dim NameA As Variant
Dim YesNoCol As Range
Dim lstRow As Long
Dim c As Range
Dim yArry, nArry

lstRow = Range("C" & Rows.Count).End(xlUp).Row
Set YesNoCol = Range("C2:C" & lstRow)

For Each c In YesNoCol
   If c = "Yes" Then
        NameA = c.Offset(, 1).Resize(, 8).Value
        yArry = Application.Index(NameA, 1, Array(1, 2, 4, 5, 6, 7, 8))
        ShtTargetYs.Range("A" & Rows.Count).End(xlUp)(2).Resize(, 7) = yArry
     ElseIf c = "No" Then
        NameA = c.Offset(, 1).Resize(, 3).Value
        nArry = Application.Index(NameA, 1, Array(1, 2, 3))
        ShtTargetNo.Range("A" & Rows.Count).End(xlUp)(2).Resize(, 3) = nArry
   End If
Next

End Sub
 
Upvote 0
Hi Howard,

Thank you so much for your help. I apologize for my delayed response. I copy-pasted that and tried to run it and nothing happened. Other macros work in this spreadsheet, but this one doesn't result in any data being moved over to the other sheets. However, it doesn't throw an error either-- it's just that nothing happens. If you have any thoughts, I would love to hear them.

Thanks again!!
Danielle

Hi Danielle,

Give this a try, copy and paste in the worksheet module of the sheet with the data on it.
Code assumes there are headers on each sheets "Mailings" & "Email_blast".

Regards,
Howard

Code:
Option Explicit

Sub ColCYesNo()
'// w/much help from Mickg @ this forum

Dim ShtTargetYs As Worksheet
Dim ShtTargetNo As Worksheet
Set ShtTargetYs = Sheets("Mailings")
Set ShtTargetNo = Sheets("Email_blast")
Dim NameA As Variant
Dim YesNoCol As Range
Dim lstRow As Long
Dim c As Range
Dim yArry, nArry

lstRow = Range("C" & Rows.Count).End(xlUp).Row
Set YesNoCol = Range("C2:C" & lstRow)

For Each c In YesNoCol
   If c = "Yes" Then
        NameA = c.Offset(, 1).Resize(, 8).Value
        yArry = Application.Index(NameA, 1, Array(1, 2, 4, 5, 6, 7, 8))
        ShtTargetYs.Range("A" & Rows.Count).End(xlUp)(2).Resize(, 7) = yArry
     ElseIf c = "No" Then
        NameA = c.Offset(, 1).Resize(, 3).Value
        nArry = Application.Index(NameA, 1, Array(1, 2, 3))
        ShtTargetNo.Range("A" & Rows.Count).End(xlUp)(2).Resize(, 3) = nArry
   End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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