VBA - search data based on Oldest & Newest Date

iris1007

New Member
Joined
Jun 28, 2017
Messages
31
Hi,
Below is the data I have.
I need to find the Customer name base on same Pre-Group & same Part, copy and paste in column E "Result". With following criteria:

1. For those with same Pre-Group & same Part:
- the Customer with oldest DATE, Column E = blank
- the Customer with 2nd oldest DATE, Column E = Customer with oldest DATE
- the Customer with 3rd oldest DATE, Column E = Customer with 2nd oldest DATE

so on and so forth....

Thanks in advance for the helps and hope to hear the good news soon.
CUSTOMERPARTDATEPre-GROUPThis should be the Result after the Code run
HONEY4073121/10/201400523
HONEYG326623/5/201100523
HONEYG326627/7/201100523HONEY
SYSEMG326616/1/201200523HONEY
SYSEMG32664/7/201300523SYSEM
HONEYG326616/12/201400523SYSEM
WUHANG326922/7/201400523
HONEYG335410/4/200800523
SYSEMG335430/3/201000523HONEY
SYSEMG335521/7/200600523
HONEYK27886/2/201700523
SHANGHAIK27892/12/201600523
HONEY265967/7/2007AA0052
HONEY2659629/3/2010AA0052HONEY
WUHAN2677125/9/2012AA0052
SYSEM2677113/2/2014AA0052WUHAN
SHANGHAI3869923/2/2017AA0052
HONEY90-2512/5/2008AA0052
HONEY90-259/12/2008AA0052HONEY
SYSEM90-2526/2/2013AA0052HONEY
SYSEMG325417/4/2013AA0052
SYSEMG325423/10/2013AA0052SYSEM
SYSEMG325424/6/2014AA0052SYSEM
HONEYG325420/8/2014AA0052SYSEM
HONEYG325420/1/2015AA0052HONEY
HONEYG325623/12/2011AA0052
HONEYG325723/12/2011AA0052
SYSEMG325715/5/2013AA0052HONEY
HONEYG325721/10/2014AA0052SYSEM
HONEYG325719/12/2014AA0052HONEY
WUHANG326118/3/2011AA0052
SYSEMG32616/6/2014AA0052WUHAN
SYSEMG326219/6/2015AA0052
HONEYG326217/3/2016AA0052SYSEM

<tbody>
</tbody><colgroup><col span="2"><col><col><col></colgroup>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,
Below is the data I have.
I need to find the Customer name base on same Pre-Group & same Part, copy and paste in column E "Result". With following criteria:

Try this:
Code:
Sub a1011914a()

Dim va, vb
Dim rr As Long
rr = ActiveSheet.Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
va = Range(Cells(2, "A"), Cells(rr, "D"))
ReDim vb(1 To rr - 1, 1 To 1)
For j = 2 To UBound(va, 1)
        If va(j, 2) = va(j - 1, 2) And va(j, 4) = va(j - 1, 4) Then
            vb(j, 1) = va(j - 1, 1)
        End If
Next
Range("E2").Resize(UBound(vb, 1), 1) = vb

End Sub
 
Upvote 0
Hi Akuini,
I have another huge file which have many Items in a same column (column B) and I would like to search at PART (column D) and assign "1" if Yes else "0"..according to Item No.
Can you help?
Thanks in advance for the helps and hope to hear from you soon.


Item NoDetailsPARTDescriptionABCDEFGHI
A2041-04 MISSING 2065-01 CRACK 73-01 Configuration 84-01 Configuration 83-03 Modification 311947A00 Modification 2041-04MISSING100000010
B18-01 MISSING 312169A00 Configuration 312130A00 Configuration 312155A00 CRACK 312161A00 Configuration 73-01 Configuration 74-01 Modification 18-01 MISSING 12A00 Configuration 26A00 MISSING 2044-01CHANGE000000000
C2065-01 CRACK 73-01 Configuration 78-01 Configuration 83-03 Modification 51-02 CHANGE 311364A00 Modification 311777A00 CRACK 312090A00 Modification 311599A00 Configuration 311241A00 CHANGE 2055-01 Configuration 18-01 MISSING 2054-01CRACK000011000
D312127A00 CRACK 312105B00 CRACK 312161A00 Configuration 311595A00 Configuration 311667A00 Modification 311471A00 MISSING 311881A00 Modification 12A00 Configuration 51-02 CHANGE 311244A00 Modification 311262A00 Modification 311312A00 Modification 2065-01 CRACK 73-01 Configuration 78-01 Configuration 2055-01Configuration001000000
E82-02 MISSING 83-03 Modification 77-01 CRACK 70-03 Configuration 2063-16 Modification 2054-01 CRACK 26A00 MISSING 14A00 CHANGE 311471A00 MISSING 311314A00 MISSING 311262A00 Modification 311244A00 Modification 311241A00 CHANGE 74-01 Modification 15A00 Modification 2063-16Modification000010100
F312090A00 Modification 311947A00 Modification 311667A00 Modification 312105B00 CRACK 312169A00 Configuration 2054-01 CRACK 77-01 CRACK 2064-01Configuration000000000
G83-03 Modification 82-02 MISSING 77-01 CRACK 2063-16 Modification 26A00 MISSING 311491A00 Configuration 2065-01CRACK101100000
H12A00 Configuration 76-01 Configuration 311241A00 CHANGE 311262A00 Modification 311313A00 Modification 311312A00 Modification 2041-04 MISSING 70-03Configuration000010000
I73-01 Configuration 312091A00 Modification 73-01Configuration111100001
74-01Modification010010000
75-01MISSING000000000
76-01Configuration000000010
77-01CRACK000011100
78-01Configuration001100000
79-01Modification000000000
81-01Configuration000000000
82-02MISSING000010100
83-03Modification101010100
84-01Configuration100000000
18-01MISSING011000000
19-01CHANGE000000000
51-02CHANGE001100000
26A00MISSING010010100
12A00Configuration010100010
14A00CHANGE000010000
15A00Modification000010000
311142A00Modification000000000
311241A00CHANGE001010010
311244A00Modification000110000
311262A00Modification000110010
311312A00Modification000100010
311313A00Modification000000010
311314A00MISSING000010000
311359A00Modification000000000
311364A00Modification001000000
311460A00CHANGE000000000
311471A00MISSING000110000
311491A00Configuration000000100
311595A00Configuration000100000
311599A00Configuration001000000
311667A00Modification000101000
311676A00Modification000000000
311721A00Modification000000000
311777A00CRACK001000000
311881A00Modification000100000
311889A00Modification000000000
311947A00Modification100001000
312002A00Modification000000000
312086A00CRACK000000000
312090A00Modification001001000
312091A00Modification000000001
312105B00CRACK000101000
312106B00Modification000000000
312121A00Modification000000000
312127A00CRACK000100000
312130A00Configuration010000000
312155A00CRACK010000000
312161A00Configuration010100000
312169A00Configuration010001000

<tbody>
</tbody><colgroup><col><col><col><col><col><col span="9"></colgroup>
 
 
Upvote 0
Hi Akuini,
I have another huge file which have many Items in a same column (column B) and I would like to search at PART (column D) and assign "1" if Yes else "0"..according to Item No.
Can you help?
Thanks in advance for the helps and hope to hear from you soon.



Ok, try this:
Code:
Sub a1011914a()
Dim i As Long, j As Long
Dim va, vb, vc

va = Range(Cells(2, "B"), Cells(10, "B")).Value
ra = Range("D:D").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
vb = Range(Cells(2, "D"), Cells(ra, "D")).Value
ReDim vc(1 To UBound(vb, 1), 1 To 9)

For i = 1 To UBound(vb, 1)
    For j = 1 To UBound(va, 1)
        If InStr(1, va(j, 1), vb(i, 1), 0) Then
            vc(i, j) = 1
                Else
            vc(i, j) = 0
        End If
    Next
Next

Range("F2").Resize(UBound(vc, 1), 9) = vc

End Sub
 
Upvote 0
Hi Akuini,
Million Thanks for your fast respond.
As this items I have in my report can be up till 10k (column A & B), was that meant I need to change the "UBound(<acronym title="vBulletin">vb</acronym>, 1), 1 To 9)"? Can the Code stop if column A is Blank?

Once again Thanks!
 
Upvote 0
Hi Akuini,
Million Thanks for your fast respond.
As this items I have in my report can be up till 10k (column A & B), was that meant I need to change the "UBound(<acronym title="vBulletin">vb</acronym>, 1), 1 To 9)"? Can the Code stop if column A is Blank?

Once again Thanks!
I don't understand. If col A & B are 10k rows, do you mean Item No will go on I,J,K .... To 10K rows? Or after Item No I it will return back to A?
 
Upvote 0
Hi Akuini,
Yes, you are right. Item No will go on I,J,K,L ......
Thanks in advance for ALL the helps.
 
Upvote 0

Forum statistics

Threads
1,216,123
Messages
6,128,975
Members
449,480
Latest member
yesitisasport

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