VBA - Comparing data and add remarks accordingly

iris1007

New Member
Joined
Jun 28, 2017
Messages
31
Hi,
I have a huge excel data which I need to compare the same Part # with same Ref # and add the "First" or "Repeat" in Remarks column, according to the Date.
Below is a sample:
[TABLE="width: 385"]
<colgroup><col width="129" style="width: 97pt; mso-width-source: userset; mso-width-alt: 4579;"> <col width="181" style="width: 136pt; mso-width-source: userset; mso-width-alt: 6428;"> <col width="122" style="width: 92pt; mso-width-source: userset; mso-width-alt: 4352;"> <col width="80" style="width: 60pt; mso-width-source: userset; mso-width-alt: 2844;"> <tbody>[TR]
[TD="width: 129, bgcolor: transparent"]DATE[/TD]
[TD="width: 181, bgcolor: transparent"]Part #[/TD]
[TD="width: 122, bgcolor: transparent"]Ref #[/TD]
[TD="width: 80, bgcolor: transparent"]Remarks[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]15/2/2016[/TD]
[TD="bgcolor: transparent"]0145-5521-1145[/TD]
[TD="bgcolor: transparent"]37Z-138804512[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]13/3/2018[/TD]
[TD="bgcolor: transparent"]0145-5521-1145[/TD]
[TD="bgcolor: transparent"]37Z-15142396[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]18/11/2016[/TD]
[TD="bgcolor: transparent"]0145-5521-1145[/TD]
[TD="bgcolor: transparent"]37Z-16548768[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]6/12/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]1145214[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]30/9/2014[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]2255551420[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]11/3/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]2255551420[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]14/12/2010[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]22523413G67[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]19/1/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]22523413G67[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]27/4/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]22523413G67[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]28/10/2014[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]22502171[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]24/6/2013[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]225762201D[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]9/6/2011[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]225F0991[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]6/9/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]225F0991[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]28/10/2011[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]22611AD123[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]27/7/2015[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]22611AD123[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]27/12/2013[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]ABC22622[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]11/5/2015[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]F23201884[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]2/8/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]F23201884[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]26/1/2017[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]F23201884[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]7/2/2012[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]A23267[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]3/12/2010[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]A23267[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]13/4/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]ZX-10-23809[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]21/8/2018[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]ZX-10-23809[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]23/7/2014[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]2-A4276-00[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]25/4/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]2-A4276-00[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]30/4/2013[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]81A-CAA26474[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]10/12/2015[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]81A-CBB26680[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]14/11/2016[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]81A-CBB26680[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]21/8/2017[/TD]
[TD="bgcolor: transparent"]07F10-150326018[/TD]
[TD="bgcolor: transparent"]81A-CDD27477[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]30/4/2013[/TD]
[TD="bgcolor: transparent"]071-50001-8102[/TD]
[TD="bgcolor: transparent"]F149120021[/TD]
[TD="bgcolor: transparent"]First[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]10/12/2016[/TD]
[TD="bgcolor: transparent"]071-50001-8102[/TD]
[TD="bgcolor: transparent"]F149120021[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]14/11/2015[/TD]
[TD="bgcolor: transparent"]071-50001-8102[/TD]
[TD="bgcolor: transparent"]F149120021[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]21/8/2017[/TD]
[TD="bgcolor: transparent"]071-50001-8102[/TD]
[TD="bgcolor: transparent"]F149120021[/TD]
[TD="bgcolor: transparent"]Repeat[/TD]
[/TR]
</tbody>[/TABLE]

Hope anyone of you can help me. Thank you!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
[TABLE="width: 1086"]
<colgroup><col><col><col><col span="2"><col><col><col></colgroup><tbody>[TR]
[TD]DATE[/TD]
[TD]Part #[/TD]
[TD]Ref #[/TD]
[TD]Remarks[/TD]
[TD][/TD]
[TD][/TD]
[TD]helper[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]15/02/2016[/TD]
[TD]0145-5521-1145[/TD]
[TD]37Z-138804512[/TD]
[TD]First[/TD]
[TD][/TD]
[TD][/TD]
[TD]0145-5521-114537Z-138804512[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]13/03/2018[/TD]
[TD]0145-5521-1145[/TD]
[TD]37Z-15142396[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]0145-5521-114537Z-15142396[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]18/11/2016[/TD]
[TD]0145-5521-1145[/TD]
[TD]37Z-16548768[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]0145-5521-114537Z-16548768[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]06/12/2016[/TD]
[TD]07F10-150326018[/TD]
[TD]1145214[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-1503260181145214[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]30/09/2014[/TD]
[TD]07F10-150326018[/TD]
[TD]2255551420[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-1503260182255551420[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]11/03/2016[/TD]
[TD]07F10-150326018[/TD]
[TD]2255551420[/TD]
[TD]repeat[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-1503260182255551420[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]14/12/2010[/TD]
[TD]07F10-150326018[/TD]
[TD]22523413G67[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-15032601822523413G67[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]19/01/2016[/TD]
[TD]07F10-150326018[/TD]
[TD]22523413G67[/TD]
[TD]repeat[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-15032601822523413G67[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]27/04/2016[/TD]
[TD]07F10-150326018[/TD]
[TD]22523413G67[/TD]
[TD]repeat[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-15032601822523413G67[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]28/10/2014[/TD]
[TD]07F10-150326018[/TD]
[TD]22502171[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-15032601822502171[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]24/06/2013[/TD]
[TD]07F10-150326018[/TD]
[TD]225762201D[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-150326018225762201D[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]09/06/2011[/TD]
[TD]07F10-150326018[/TD]
[TD]225F0991[/TD]
[TD]first[/TD]
[TD][/TD]
[TD][/TD]
[TD]07F10-150326018225F0991[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]col G[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 3"]some ref numbers are text others are numbers[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]I have corrected that[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]clearly the first row must be a first[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]formula used to determine the "first" in D3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 4"]=IF(SUMPRODUCT(($G$2:G2=G3)*1)=0,"first","repeat")[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Another option
In D2 copied down
=IF(COUNTIFS($B$2:$B2,B2,$C$2:$C2,C2)=1,"First","Repeat")
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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