Match,Difference and Copy VB Issue

tchan05

New Member
Joined
Dec 20, 2020
Messages
3
Office Version
  1. 2013
Platform
  1. Windows
Hello,

I am new to this forum and very new to VB. I would like to write a VB Code to do the following: I have Sheet1 that has four columns with headers. Column A and B data goes together and column C and D data goes together. What I would like to do is 1) have Column C find Match in Column B and display difference on to sheet2 but need Column A to display the names as wee. Next I would like to do reverse and have Column B match column C and display difference on to sheet 2 but need corresponding column D names to match the results as well. The code I have so far only display the badge numbers on column E and F ( I realized that the results did not go on to sheet 2, just testing to on the same sheet at this point). What's pulling hair at this point is that Column C and D contains duplicates, but I would like to results to show one name and badge number. The code below is what I have so far and from this point, I am confused and going crazy. Please advise and help.

Sub DisplayUniques()


Dim rngCell As Range


For Each rngCell In Range("B2:B99")
If WorksheetFunction.CountIf(Range("C2:C99"), rngCell) = 0 Then
Range("E" & Rows.Count).End(xlUp).Offset(1) = rngCell
End If
Next
For Each rngCell In Range("C2:C99")
If WorksheetFunction.CountIf(Range("B2:B99"), rngCell) = 1 Then
Range("F" & Rows.Count).End(xlUp).Offset(1) = rngCell
End If
Next

End Sub

Here's what my data looks like:
Employee InBadge NumberBadge NumberEmp Name
ARIAS, FRANCISCO E (A004)801412080Jasper Grimaldo
BALLESTEROS, MIGUEL VIDAL (A5CX)1198516011Adal Betanzos
BEASLEY, ZACKARY (AD7Y)858016011Adal Betanzos
BERMUDEZ, NOE ADALBERTO (ABRH)620013276Alberto Torres
BETANZOS, ADAL VOLT (AD31)1601113276Alberto Torres
BONNER, ERYN HELENA (A5CD)99058635Andreas Villegas
BROWN, JAHEEME SEMAJ (AD7X)154348789Anthony Gutierrez
BUCIO-GARCIA, HAIRI (A75P)133208789Anthony Gutierrez
BUI, HUY NGUYEN (A011)763521700Arturo Santana
BYRD WHEELER, JESSICA EVELYN (A013)74816897Augustine Silva
CHA, ELY JJ (ACP3)862018022Beatrice Orozco
CHANHMANY, SUH (A017)759718067Chia Xyong
CIRILO, JOEL SELECT (AD1K)167256595Chu Her
CORRALES, MIRANDA CIARA (ACUP)171608620Ely Cha
CORRALES, RANDY REUBEN (ACJH)1786510931Enrique Martinez
DECKER, MISTY DAWN (AACF)1635212747Erik Nieto
ERICKSON, ILENE ANINA (AAOQ)69688014Frank Arias
GALINDO, GRISELDA (A5OO)93429342Griselda Galindo
GALINDO, JACQUELIN GIOVANA (ABJJ)67539342Griselda Galindo
GARCIA, STEVEN (A028)31449342Griselda Galindo
GOMEZ, JOSE MANUEL (A034)76277635Huy Bui
GONZALEZ, RICARDO (A037)80626968Ilene Erickson
GRIMALDO, JASPER VOLT (AD6M)1208013473Joseph Tapia
GUTIERREZ, ANTHONY DARWIN (A1CM)878913473Joseph Tapia
HAGAN, ANDRES VOLT (AD6K)1115027337Kenneth Yang
HER, CHU (A046)659518556Kia Xiong
HER, PHENG ALEX (A9GR)59769088Kou Yang
HER, YANG (A047)181711416Laura Cantor
HERRERA, LUIS FELIPE (AD04)50771416Laura Cantor
HINOJOSA MORALES, RAUL ANTONIO (A7WT)105095077Luis Herrera
HOBBS, LYRICK SELECT (AD4V)1474014740Lyrick Hobbs
HYDER, ROBERT EDWARD (A7OJ)1277210017Macy Xiong
JACKSON, WILLIAM EDWARD (ACKW)607611261Markys Rivera
LEE, MICKY (A6UV)686517218Martha Tascon
LOPEZ, GEORGE MANUEL (ABNB)91801461Melissa Perez
LOR, BAO (AD59)230061461Melissa Perez
LOZANO JR, STEVEN (ABAM)81461461Melissa Perez
MARTINEZ, ENRIQUE VOLT (AD2P)1093111985Miguel Ballesteros
MEDINA, CONNIEFRANCES CLORINDA (A3BC)695811985Miguel Ballesteros
MENDOZA, LAURA (A3OQ)141617160Miranda Corrales
MINNIEWEATHER JR, ROBERT LEE (A3B6)23883494Nicholas Silva
MONTOYA, TYLER AVERY (ACL6)68237816Pamela Yang
NIETO, ERIK SELECT (ACZW)127475976Pheng Her
OROZCO, BEATRICE (A085)180225976Pheng Her
ORTEGA, RICHARD SELECT (AD2N)88295976Pheng Her
OUK, RY (A1A8)490017865Randy Corrales
PEREZ, MELISSA (ACUS)146110509Raul Morales
PEREZ, REBECCA KRISTINE (ACJX)1208510509Raul Morales
PUENTE, GERARDO PARTNERS (AD2T)2634910509Raul Morales
REYES HERRERA, MARTIN (AAWE)43538879Raul Rodriguez
RICO, ANGIE (A102)73378879Raul Rodriguez
RIVERA, MARCOS A (A104)181228879Raul Rodriguez
RIVERA, MARKYS ALEXANDER (AD13)1126111896Robert Vang
RODRIGUEZ, AMBER DANIELLE (AB77)190808714Sam Vong Xiong
RODRIGUEZ, RAUL MENDOZA (ABFE)88798714Sam Vong Xiong
ROSALES, JASON (A3B7)244219169Sandy Sanouvong
SANCHEZ, SERENA FELICIA (ACO0)1285219169Sandy Sanouvong
SANOUVONG, SANDY (A7L7)1916919169Sandy Sanouvong
SANTANA, ARTURO (AD97)217004141Sara Nou Lee Xiong
SEM, SUNNY ROTH (AD5N)95859585Sunny Sem
SILVA, AUGUSTINE CAUSTRITA (AATT)68971630Tony Torrez
SILVA, NICHOLAS STORM (A9KZ)34942767Touchershee Yang
TAPIA, JOSEPH (ACWN)134732767Touchershee Yang
TASCON, MARTHA ROTH (AD3U)172182767Touchershee Yang
TORRES, ALBERTO (AD2S)132766823Tyler Montoya
TORREZ, TONY JR (AAVF)16304888Vang Yee
UNG, PINA (A5CW)19476076William Jackson
VANDERLAAN, WILLIAM (AAT4)1079418171Yang Her
VANG, ANNRIE (A7C0)1371
VANG, GAO HLEE (A7X2)1486
VANG, MARK (A126)7995
VANG, ROBERT (A6GN)11896
VANG, YEE (A4JP)4888
VERDUGO, JESSE RICHARD (ACZN)4299
VIGIL, ANTHONY ALBERT (A130)72352
VILLA, ABRAN (A131)18013
VILLEGAS, ANDREAS FIDENCIO (A1J6)8635
WASHINGTON, ARSHEAL OKEITH (A6QE)2027
XIONG, CHEE NOU JOHNNY (A24W)14333
XIONG, KIA (AAKC)18556
XIONG, MACY (A7NU)10017
XIONG, SAM VONG (A11A)8714
XIONG, SARA NOU LEE (A6CR)4141
XYONG, CHIA (A138)18067
YANG, KENNETH HU CHEE (AC4Q)27337
YANG, KOMOCHAN (A7FB)5812
YANG, KOU (A11D)9088
YANG, PAMELA (A144)7816
YANG, TOUCHERSHEE JONATHAN (ACX4)2767
YANG, YEELENG (AA1I)0435
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You can substitute the actual sheet names for the index numbers I used.

VBA Code:
Sub t()
Dim c As Range
    With Sheets(1) 'Edit sheet name
        For Each c In .Range("B2", .Cells(Rows.Count, 2).End(xlUp))
            If Application.CountIf(.Range("C:C"), c.Value) = 0 Then
                .Range("A" & c.Row).Resize(, 2).Copy Sheets(2).Cells(Rows.Count, 1).End(xlUp)(2)
            End If
        Next
    For Each c In .Range("C2", .Cells(Rows.Count, 3).End(xlUp))
            If Application.CountIf(.Range("B:B"), c.Value) = 0 Then
                .Range("C" & c.Row).Resize(, 2).Copy Sheets(2).Cells(Rows.Count, 3).End(xlUp)(2)
            End If
        Next
    End With
End Sub
 
Upvote 0
Wow! Thank you so much. I see where my approach wasn’t working and where I looked at it wrong. Thank you again...I gotta tell my co- workers to register. You are awesome!
 
Upvote 0
Wow! Thank you so much. I see where my approach wasn’t working and where I looked at it wrong. Thank you again...I gotta tell my co- workers to register. You are awesome!
Tell your coworkers that when they register to be sure and read the posting guidlines and forum rules. Too many ignore those two items when joining the forum and do not get good results in their first few posts because they ignored them.

Thanks for the feedback,
Regards, JLG
 
Upvote 0
Solution
Thank you, will do...as a matter of fact, we were browsing through the site this morning and getting a better feel of the requirements. Thank you again.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,709
Members
449,331
Latest member
smckenzie2016

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