DataBlake
Well-known Member
- Joined
- Jan 26, 2015
- Messages
- 781
- Office Version
- 2016
- Platform
- Windows
Hey i'm having some trouble identifying an issue with a dictionary that is returning a key its not supposed to have
I've checked over my code 9 times and tried isolating the problem by commenting out the 2nd dictionary that's causing the problem to no avail.
I have a sub that opens a workbook called "Dictionaries.xlsm" which opens relevant info, loads keys and their values with that data, and then closes the workbook
I then use a seperate sub to open the workbook again and do the same thing but with different data
Specifically i have 10 vendors each with data for quantities and pricing (separate files).
With one of my vendors it is loading the price of a few part number that do not exist in the quantity file (but do exist in the pricing file) into the quantity dictionary. Its not like EVERY part number that exists in one is overlapping into the other, just a few. Can you think of anything that would cause an issue like this? I can't include any real example as its a complex system and i don't want to post 18 subs and 20 vendor sheets, but here is how i have things set up in a tl;dr way.
All dictionaries are declared as public in the XLSB
i have a checklist in the beginning of my main workbook, after its completed it calls XLSB macros like so
These XLSB macros open the Dictionaries.xlsm file and runs the macro to import the proper data (quantities or prices, i've tested getQTY and getPRICE and they both work as intended)
(after the data is imported to the Dictionaries.xlsm) i loop through the sheets (x) and add to the dictionary. MTT and RTT are vendor's data, but i cut the other vendors out of the if statement as MTT is where the problem is occuring
see openWB gets closed and then i redo the process for pricing
I just don't see any overlap but when i search a specific part number that doesn't exist within the quantity data i get the price for that part number
but here is where it gets weird(er). Its not EVERY part number that doesn't exist in the quantity data gets mixed up with price.
So here is what the quantity file looks like
and heres what the pricing file looks like
B356026359035545 (column F in pricing) does not exist in the quantity file, this is the part number that displays the PRICE when i use the findQTY sub
So if i enter in this part number into the msgbox i get "484" rather than blank, 0, or "no quantity available"
yet B35664635908945 does not exist in the quantity file either but when i search for the part number its just blank? it doesn't show the error message i wrote but its a blank text box with "ok"
I understand that this is long winded and confusing for someone not looking at what i'm looking at, but if you can help i will cry happy tears.
I've checked over my code 9 times and tried isolating the problem by commenting out the 2nd dictionary that's causing the problem to no avail.
I have a sub that opens a workbook called "Dictionaries.xlsm" which opens relevant info, loads keys and their values with that data, and then closes the workbook
I then use a seperate sub to open the workbook again and do the same thing but with different data
Specifically i have 10 vendors each with data for quantities and pricing (separate files).
With one of my vendors it is loading the price of a few part number that do not exist in the quantity file (but do exist in the pricing file) into the quantity dictionary. Its not like EVERY part number that exists in one is overlapping into the other, just a few. Can you think of anything that would cause an issue like this? I can't include any real example as its a complex system and i don't want to post 18 subs and 20 vendor sheets, but here is how i have things set up in a tl;dr way.
All dictionaries are declared as public in the XLSB
i have a checklist in the beginning of my main workbook, after its completed it calls XLSB macros like so
Code:
'Update Quantity Dictionary
Application.Run "PERSONAL.XLSB!dictionaryQTY"
'Update Price Dictionary
Application.Run "PERSONAL.XLSB!dictionaryPRICE"
These XLSB macros open the Dictionaries.xlsm file and runs the macro to import the proper data (quantities or prices, i've tested getQTY and getPRICE and they both work as intended)
Code:
filePATH = "C:\Users\username\Desktop\Excel Program\Dictionaries.xlsm"
Set openWB = Application.Workbooks.Open(filePATH)
Application.Run ("'Dictionaries.xlsm'!getQTY")
Set ws = openWB.Worksheets("QTY")
Set dicQTY = CreateObject("scripting.dictionary")
(after the data is imported to the Dictionaries.xlsm) i loop through the sheets (x) and add to the dictionary. MTT and RTT are vendor's data, but i cut the other vendors out of the if statement as MTT is where the problem is occuring
Code:
For x = Worksheets("QTY").Index + 1 To Worksheets("IMG").Index - 1
With Sheets(x)
ary1 = .Range("A1").CurrentRegion.Value2
End With
For i = 2 To UBound(ary1)
If x = Sheets("MTT").Index Or x = Sheets("RTT").Index Then
If Not dicQTY.exists(ary1(i, 1)) Then dicQTY.Add ary1(i, 1), ary1(i, 2)
Else
End If
Next i
Next x
openWB.Close False
see openWB gets closed and then i redo the process for pricing
Code:
filePATH = "C:\Users\username\Desktop\Excel Program\Dictionaries.xlsm"
Set openWB = Application.Workbooks.Open(filePATH)
Application.Run ("'Dictionaries.xlsm'!getPRICE")
Set ws = openWB.Worksheets("QTY")
Set dicPRICE = CreateObject("scripting.dictionary")
For x = Worksheets("QTY").Index + 1 To Worksheets("IMG").Index - 1
With Sheets(x)
ary1 = .Range("A1").CurrentRegion.Value2
End With
For i = 2 To UBound(ary1)
If x = Sheets("MTT").Index Then
If Not dicPRICE.exists(ary1(i, 6)) Then dicPRICE.Add ary1(i, 6), ary1(i, 8)
Else
End If
Next i
Next x
openWB.Close False
I just don't see any overlap but when i search a specific part number that doesn't exist within the quantity data i get the price for that part number
Code:
Sub findQTY()
Dim pnum As Variant
pnum = InputBox("Please Type in the part number")
If IsNumeric(pnum) Then pnum = CLng(pnum)
If dicQTY.exists(pnum) = True Then
MsgBox dicQTY(pnum)
Else
MsgBox "No quantity available for this part number"
End If
End Sub
but here is where it gets weird(er). Its not EVERY part number that doesn't exist in the quantity data gets mixed up with price.
So here is what the quantity file looks like
Book1 | ||||
---|---|---|---|---|
A | B | |||
2 | B600635905645 | 15 | ||
3 | B6006359035536 | 19 | ||
4 | B6006359035545 | 17 | ||
5 | B600635908445 | 42 | ||
6 | B600635908945 | 4 | ||
7 | B606635905645 | 4 | ||
8 | B6066359035536 | 39 | ||
9 | B6066359035545 | 61 | ||
10 | B606635908445 | 9 | ||
11 | B606635908945 | 16 | ||
12 | B663635905645 | 24 | ||
MHT_Invt_Total_USA (00000016) |
and heres what the pricing file looks like
Book1 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
2 | MTT | 1P | Orderable | B7100 | Clemensport Reboot | B35600635905645 | Clemensport Reboot | 501 | ||
3 | MTT | 1P | Orderable | B7100 | Clemensport Reboot | B356006359035536 | Clemensport Reboot | 501 | ||
4 | MTT | 1P | Orderable | B7100 | Clemensport Reboot | B600635905645 | Clemensport Reboot | 501 | ||
5 | MTT | 1P | Orderable | B7100 | Clemensport Reboot | B6006359035536 | Clemensport Reboot | 501 | ||
6 | MTT | 1P | Orderable | B7100 | Clemensport Reboot | B35600635908945 | Clemensport Reboot | 501 | ||
7 | MTT | 1P | Orderable | B7101 | Clemensport Reboot | B35606635905645 | Clemensport Reboot | 484 | ||
8 | MTT | 1P | Orderable | B7101 | Clemensport Reboot | B356066359035536 | Clemensport Reboot | 484 | ||
9 | MTT | 1P | Orderable | B7101 | Clemensport Reboot | B356066359035545 | Clemensport Reboot | 484 | ||
10 | MTT | 1P | Orderable | B7101 | Clemensport Reboot | B606635905645 | Clemensport Reboot | 484 | ||
11 | MTT | 1P | Orderable | B7101 | Clemensport Reboot | B35606635908945 | Clemensport Reboot | 484 | ||
12 | MTT | 1P | Orderable | B7102 | Clemensport Reboot | B356026359035536 | Clemensport Reboot | 484 | ||
13 | MTT | 1P | Orderable | B7102 | Clemensport Reboot | B356026359035545 | Clemensport Reboot | 484 | ||
14 | MTT | 1P | Orderable | B7102 | Clemensport Reboot | B35602635908445 | Clemensport Reboot | 484 | ||
15 | MTT | 1P | Orderable | B7113 | Ridensport Reboot | B35663635905645 | Ridensport Reboot | 501 | ||
16 | MTT | 1P | Orderable | B7113 | Ridensport Reboot | B356636359035536 | Ridensport Reboot | 501 | ||
17 | MTT | 1P | Orderable | B7113 | Ridensport Reboot | B6006359035545 | Ridensport Reboot | 501 | ||
18 | MTT | 1P | Orderable | B7113 | Ridensport Reboot | B35663635908445 | Ridensport Reboot | 501 | ||
19 | MTT | 1P | Orderable | B7113 | Ridensport Reboot | B35663635908945 | Ridensport Reboot | 501 | ||
20 | MTT | 1P | Orderable | B7114 | Ridensport Reboot | B35664635905645 | Ridensport Reboot | 484 | ||
21 | MTT | 1P | Orderable | B7114 | Ridensport Reboot | B6066359035536 | Ridensport Reboot | 484 | ||
22 | MTT | 1P | Orderable | B7114 | Ridensport Reboot | B600635908945 | Ridensport Reboot | 484 | ||
23 | MTT | 1P | Orderable | B7114 | Ridensport Reboot | B600635908445 | Ridensport Reboot | 484 | ||
24 | MTT | 1P | Orderable | B7114 | Ridensport Reboot | B35664635908945 | Ridensport Reboot | 484 | ||
Sheet1 |
B356026359035545 (column F in pricing) does not exist in the quantity file, this is the part number that displays the PRICE when i use the findQTY sub
So if i enter in this part number into the msgbox i get "484" rather than blank, 0, or "no quantity available"
yet B35664635908945 does not exist in the quantity file either but when i search for the part number its just blank? it doesn't show the error message i wrote but its a blank text box with "ok"
I understand that this is long winded and confusing for someone not looking at what i'm looking at, but if you can help i will cry happy tears.