Using VBA Match and Index function
- DarrenSmith1981
- Thread is marked as Resolved.
-
-
Imagine my surprise to discover that the code we have been discussing isn't in that file.
-
On the user form if you go to the Reset_Drawing_Numbers combo box it`s there
-
-
This "Set ODict = GetDictionary(matchRange, 1, 2)" seems to be the issue it seems to say nothing.
Should it be filling in with the cell values from the parts List?
I`ve added your code above but still no luck?
-
-
Try this - it works for me once I added some data that matched up to the part list:
Code
Display MorePrivate Sub Reset_Drawing_Numbers_Change() Dim matchRange As Range Dim ODict As Object Dim cmb As ComboBox Dim PartsListLastRow As Long, DestLastRow As Long Dim wsSource As Worksheet, wsDest As Worksheet Set wsSource = ThisWorkbook.Worksheets("Parts List") Set wsDest = ThisWorkbook.Worksheets("Job Card Master") Set cmb = Me.Reset_Drawing_Numbers PartsListLastRow = wsSource.Range("A" & Rows.Count).End(xlUp).Row DestLastRow = wsDest.Range("A" & Rows.Count).End(xlUp).Row Set matchRange = wsSource.Range("E1:F" & PartsListLastRow) Set ODict = GetDictionary(matchRange, 1, 2) Select Case cmb.Value Dim DataRange As Range Case ("Reset Drawing No. 1 Page") Set DataRange = wsDest.Range("A13:Q" & DestLastRow) Case ("Reset Drawing No. 2 Page") Set DataRange = wsDest.Range("A13:Q61,A66:Q" & DestLastRow) Case ("Reset Drawing No. 3 Page") Set DataRange = wsDest.Range("A13:Q61,A66:Q122,A127:Q" & DestLastRow) Case ("Reset Drawing No. 4 Page") Set DataRange = wsDest.Range("A13:Q61,A66:Q122,A127:Q183,A188:Q" & DestLastRow) Case ("Reset Drawing No. 5 Page") Set DataRange = wsDest.Range("A13:Q61,A66:Q122,A127:Q183,A188:Q244,A249:Q" & DestLastRow) End Select If Not DataRange Is Nothing Then Dim area As Range For Each area In DataRange.Areas GetPartInfoForRange area.Columns(5), area.Columns(2), ODict Next area End If End Sub Sub GetPartInfoForRange(lookupRange As Range, outputRange As Range, DataSet As Object) Dim cell As Range Dim counter As Long Dim ODict As Object For Each cell In lookupRange.Cells counter = counter + 1 outputRange.Cells(counter) = GetPartInfo(DataSet, cell.Value) Next cell End Sub Private Function GetDictionary(rng As Range, keyCol As Long, valCol As Long) As Object Dim rCell As Range Dim ODict As Object Dim keyCells As Range Set keyCells = rng.Columns(keyCol).Cells Dim valueCells As Range Set valueCells = rng.Columns(valCol).Cells Set ODict = CreateObject("Scripting.Dictionary") For Each rCell In keyCells Dim counter As Long counter = counter + 1 If Not ODict.Exists(rCell.Value) Then ODict.Add rCell.Value, valueCells.Cells(counter).Value End If Next rCell Set GetDictionary = ODict End Function
-
Terribly sorry but after I changed my Data to match still no luck
-
Please post your updated workbook then. As I said, it worked for me.
-
-
First, there's no data in the job sheet in that file. Second, why do you keep changing the code I give you?
-
-
Sorry data is back on the sheets
I changed the below. Not aware of any more changes
The data in PartsList Range E F is 1 & 2 columns in the range is this right
GetPartInfoForRange area.Columns(1), area.Columns(2), ODict
-
No, it should have stayed as I had it.
-
Very sorry now works fine sorry to waste your time.
The 5 referred to the 5th column in the Job Card Master Sheet I see what you mean.
-
Sorry seems to have stopped working
This line says Sub or Function not Defined?
outputRange.Cells(counter) = GetPartInfo(DataSet, cell.Value)
Sub GetPartInfoForRange(lookupRange As Range, outputRange As Range, DataSet As Object)
Dim cell As Range
Dim counter As Long
Dim ODict As Object
For Each cell In lookupRange.Cells
counter = counter + 1
outputRange.Cells(counter) = GetPartInfo(DataSet, cell.Value)
Next cell
End Sub
-
It would only say that if you removed the GetPartInfo function code.
-
-
Sorry your right somehow it got deleted now it`s fine
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!