Match based on a lookup and then flag
It works like a charm. However, ini trying to learn more from this, I
have some questions.
The line of code in the For next loop
What exactly is this doing?
vD1(j, 2) = vD1(j, 3): vD1(j, 3) = ""
And in the double loop through both sheet1 and sheet2, I guess I am
not following that either. The (k,2) and (j,1) refer to dimensions -
same as columns in this case on the 2 sheets??
For j = LBound(vD2) To UBound(vD2)
For k = LBound(vD1) To UBound(vD1)
If vD1(k, 2) = vD2(j, 1) _
And vD1(k, 3) = "" _
Then vD1(k, 3) = vD2(j, 3): Exit For
Next 'k
Next 'j
Sub CombineData()
* 'Get data from sheets
* Dim vD1, vD2, sAddr As String
* vD1 = Sheets("Sheet1").UsedRange
* vD2 = Sheets("Sheet2").UsedRange
* sAddr = Sheets("Sheet1").UsedRange.Address
* 'Config data for output
* Dim j As Long, k As Long
* For j = LBound(vD1) To UBound(vD1)
* * vD1(j, 2) = vD1(j, 3): vD1(j, 3) = ""
* Next 'j
* For j = LBound(vD2) To UBound(vD2)
* * For k = LBound(vD1) To UBound(vD1)
* * * If vD1(k, 2) = vD2(j, 1) _
* * * * * And vD1(k, 3) = "" _
* * * * * Then vD1(k, 3) = vD2(j, 3): Exit For
* * Next 'k
* Next 'j
* 'Dump the data into Sheet3
* Sheets("Sheet3").Range(sAddr) = vD1
End Sub
--
Garry
Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
|