Hi Team ,
Need dictionary help, I want unique account Number ,
By comparing current months column to Previous Columns and vice versa.
Also I want Dictionary Items of that account no.
Below is my attempted code, which help in extracting unique account by Comparing both the Columns.
in G AND in Column J.
Input Data,
Expected Output , Column g and J able to extract via vba,
Got salesman by manually vlookup. Thanks
Thanks
mg
Need dictionary help, I want unique account Number ,
By comparing current months column to Previous Columns and vice versa.
Also I want Dictionary Items of that account no.
Below is my attempted code, which help in extracting unique account by Comparing both the Columns.
in G AND in Column J.
VBA Code:
Sub Add_Unique_Value()
Dim sht_C As Worksheet
Set sht = ThisWorkbook.Worksheets(1)
Dim ary_base As Variant
Dim ary_Compare As Variant
'Store two Columns into Array
With sht
ary_base = .Range(.Cells(2, 1), .Cells(Rows.Count, 1).End(xlUp)).Value2
End With
With sht
ary_Compare = .Range(.Cells(2, 2), .Cells(Rows.Count, 2).End(xlUp)).Value2
End With
Dim dict_CurrentMonth As Dictionary
Set dict_CurrentMonth = Compare2List(ary_Compare, ary_base)
sht.Range("d2").Resize(dict_CurrentMonth.Count).Value = Application.Transpose(dict_CurrentMonth.Keys)
Dim Dict_PreviousMonth As Dictionary
Set Dict_PreviousMonth = Compare2List(ary_base, ary_Compare)
sht.Range("F2").Resize(Dict_PreviousMonth.Count).Value = Application.Transpose(Dict_PreviousMonth.Keys)
End Sub
Public Function Compare2List(ary_base As Variant, ary_Compare As Variant) As Dictionary
Dim i As Long
Dim Dict As New Scripting.Dictionary
With Dict
For i = LBound(ary_base) To UBound(ary_base)
.Item(ary_base(i, 1)) = "Empty"
.Item(ary_base(i, 1)) = Array(ary_base(i, 1))
Next i
For i = LBound(ary_Compare) To UBound(ary_Compare)
If .Exists(ary_Compare(i, 1)) Then .Remove (ary_Compare(i, 1))
Next i
End With
Set Compare2List = Dict
End Function
Input Data,
Book1 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | Previous Months Account Number | Sales Man | Current Months Account Number | SalesMan | |||
2 | 70 | Dhoni | 27 | Dhoni | |||
3 | 10 | sachin | 36 | sachin | |||
4 | 20 | Sehwag | 39 | Sehwag | |||
5 | 90 | Deepika | 19 | Deepika | |||
6 | 30 | Katrina | 28 | Katrina | |||
7 | 70 | Saif | 30 | Saif | |||
8 | 80 | Sharukh | 31 | Sharukh | |||
9 | 20 | Jadeja | 24 | Jadeja | |||
10 | 10 | Pranay | 18 | Pranay | |||
11 | 90 | Vinay | 22 | Vinay | |||
12 | 30 | Ponting | 38 | Ponting | |||
13 | 90 | Petersen | 80 | Petersen | |||
14 | 40 | Gilchrist | 16 | Gilchrist | |||
15 | 90 | Dravid | 21 | Dravid | |||
16 | 40 | Lara | 23 | Dhoni | |||
17 | 17 | sachin | |||||
18 | 35 | Sehwag | |||||
19 | 32 | Deepika | |||||
20 | 32 | Katrina | |||||
21 | 32 | Saif | |||||
22 | 32 | Sharukh | |||||
23 | 32 | Jadeja | |||||
24 | 32 | Pranay | |||||
25 | 32 | Vinay | |||||
26 | 32 | Ponting | |||||
27 | 32 | Petersen | |||||
Sheet1 |
Expected Output , Column g and J able to extract via vba,
Got salesman by manually vlookup. Thanks
Book1 | |||||||
---|---|---|---|---|---|---|---|
G | H | I | J | K | |||
1 | Current Months Record not Found in Previous | SalesMan | Previous Months Record not Found in Previous | SalesMan | |||
2 | 27 | Dhoni | 70 | Dhoni | |||
3 | 36 | sachin | 10 | sachin | |||
4 | 39 | Sehwag | 20 | Sehwag | |||
5 | 19 | Deepika | 90 | Deepika | |||
6 | 28 | Katrina | 40 | Gilchrist | |||
7 | 31 | Sharukh | |||||
8 | 24 | Jadeja | |||||
9 | 18 | Pranay | |||||
10 | 22 | Vinay | |||||
11 | 38 | Ponting | |||||
12 | 16 | Gilchrist | |||||
13 | 21 | Dravid | |||||
14 | 23 | Dhoni | |||||
15 | 17 | sachin | |||||
16 | 35 | Sehwag | |||||
17 | 32 | Deepika | |||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
H2:H17 | H2 | =VLOOKUP(G2,$D$2:$E$27,2,0) |
Thanks
mg