excel_1317
Board Regular
- Joined
- Jun 28, 2010
- Messages
- 212
In Below table, Column A has company names and column B has IDs. Column C and Column D contains Lookup Values which i need to lookup in Column B.
Here is a code that needs to be amended so that it takes columns C and D. Presently the code takes values from ONLY from Column C and lookup in Column A. Please HELP....
Sheet1
<thead>
</thead><tbody>
</tbody>Excel 2010
Here is a code that needs to be amended so that it takes columns C and D. Presently the code takes values from ONLY from Column C and lookup in Column A. Please HELP....
Code:
Sub ProcessLookUpValues()
Dim X As Long, Z As Long, Index As Long
Dim ArrLookUp As Variant, ArrIn As Variant, ArrOut As Variant, Counts As Variant
Columns("D:G").ClearContents
ArrLookUp = Range("C2:C" & Cells(Rows.Count, "C").End(xlUp).Row)
ReDim Counts(1 To UBound(ArrLookUp), 1 To 1)
ArrIn = Range("A2:B" & Cells(Rows.Count, "A").End(xlUp).Row)
ReDim ArrOut(1 To UBound(ArrIn) + UBound(ArrLookUp), 1 To 3)
For Z = 1 To UBound(ArrLookUp)
For X = 1 To UBound(ArrIn)
If UCase(ArrIn(X, 1)) Like "*" & UCase(ArrLookUp(Z, 1)) & "*" Then
Counts(Z, 1) = Counts(Z, 1) + 1
Index = Index + 1
ArrOut(Index, 1) = ArrIn(X, 1)
ArrOut(Index, 2) = ArrIn(X, 2)
ArrOut(Index, 3) = ArrLookUp(Z, 1)
End If
Next
Index = Index + 1
Next
Range("D1:G1") = Array("Count of Lookup Value", "Result 1", "Result 2", "Result 3 (Lookup Value")
Range("D2:D" & 1 + UBound(ArrLookUp)) = Counts
Range("E2:G" & UBound(ArrOut)) = ArrOut
End Sub
Sheet1
A | B | C | D | E | F | G | H | |
---|---|---|---|---|---|---|---|---|
1 | Table Array | Company ID | Lookup Value | Lookup Value 2 | Count of Lookup Value | Result 1 | Result 2 | Result 3 (Lookup Value 1 and Lookup Value 2) |
2 | ABC | 1 | Microsoft | 5 | Microsoft corp | 12 | Microsoft | |
3 | Microsoft corp | 12 | Coca | 3 | Microsoft | 8 | Microsoft | |
4 | Raytheon Company | 35 | FISH | Richardson | 2 | Microsoft Corporation | 9 | Microsoft |
5 | FGH | 10 | FGH | 2 | Microsoft | 6 | Microsoft | |
6 | Microsoft | 8 | Raytheon | 2 | Microsoft. | 3 | Microsoft | |
7 | Microsoft Corporation | 9 | FOLEY | Hoag | 3 | |||
8 | Microsoft | 6 | CARLSON | GASKEY | 2 | Coca | 11 | Coca |
9 | Coca | 11 | Francis | Bozicevic | 2 | Coca Cola | 2 | Coca |
10 | Microsoft. | 3 | Honeywell | 0 | Coca Cola. | 4 | Coca | |
11 | Coca Cola | 2 | ||||||
12 | Coca Cola. | 4 | FISH & RICHARDSON P.C. | 45 | FISH Richardson | |||
13 | Raytheon | 25 | Richardson Fish PC | 75 | FISH Richardson | |||
14 | FOLEY HOAG LLP | 43 | ||||||
15 | FISH & RICHARDSON P.C. | 45 | FGH | 10 | FGH | |||
16 | BOZICEVIC FIELD & FRANCIS | 52 | FGH Inc | 89 | FGH | |||
17 | CARLSON GASKEY & OLDS | 60 | ||||||
18 | Foley LLP | 57 | Raytheon Company | 35 | Raytheon | |||
19 | Richardson Fish PC | 75 | Raytheon | 25 | Raytheon | |||
20 | Richardson PC | 71 | ||||||
21 | Field & Francis Bozicevic LLP | 85 | ||||||
22 | FGH Inc | 89 | FOLEY HOAG LLP | 43 | FOLEY Hoag | |||
23 | Francis Bozicevic LLP | 90 | Foley & Hoag | 13 | FOLEY Hoag | |||
24 | GASKEY & OLDS CARLSON | 92 | Hoag and Foley | 14 | FOLEY Hoag | |||
25 | Foley & Hoag | 13 | ||||||
26 | Hoag and Foley | 14 | ||||||
27 | CARLSON GASKEY & OLDS | 60 | CARLSON GASKEY | |||||
28 | GASKEY & OLDS CARLSON | 92 | CARLSON GASKEY | |||||
29 | ||||||||
30 | Field & Francis Bozicevic LLP | 85 | Francis Bozicevic | |||||
31 | BOZICEVIC FIELD & FRANCIS | 52 | Francis Bozicevic |
<thead>
</thead><tbody>
</tbody>