Dictionary Overlap Problem

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
781
Office Version
  1. 2016
Platform
  1. 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

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
AB
2B60063590564515
3B600635903553619
4B600635903554517
5B60063590844542
6B6006359089454
7B6066359056454
8B606635903553639
9B606635903554561
10B6066359084459
11B60663590894516
12B66363590564524
MHT_Invt_Total_USA (00000016)


and heres what the pricing file looks like


Book1
ABCDEFGH
2MTT1POrderableB7100Clemensport RebootB35600635905645Clemensport Reboot501
3MTT1POrderableB7100Clemensport RebootB356006359035536Clemensport Reboot501
4MTT1POrderableB7100Clemensport RebootB600635905645Clemensport Reboot501
5MTT1POrderableB7100Clemensport RebootB6006359035536Clemensport Reboot501
6MTT1POrderableB7100Clemensport RebootB35600635908945Clemensport Reboot501
7MTT1POrderableB7101Clemensport RebootB35606635905645Clemensport Reboot484
8MTT1POrderableB7101Clemensport RebootB356066359035536Clemensport Reboot484
9MTT1POrderableB7101Clemensport RebootB356066359035545Clemensport Reboot484
10MTT1POrderableB7101Clemensport RebootB606635905645Clemensport Reboot484
11MTT1POrderableB7101Clemensport RebootB35606635908945Clemensport Reboot484
12MTT1POrderableB7102Clemensport RebootB356026359035536Clemensport Reboot484
13MTT1POrderableB7102Clemensport RebootB356026359035545Clemensport Reboot484
14MTT1POrderableB7102Clemensport RebootB35602635908445Clemensport Reboot484
15MTT1POrderableB7113Ridensport RebootB35663635905645Ridensport Reboot501
16MTT1POrderableB7113Ridensport RebootB356636359035536Ridensport Reboot501
17MTT1POrderableB7113Ridensport RebootB6006359035545Ridensport Reboot501
18MTT1POrderableB7113Ridensport RebootB35663635908445Ridensport Reboot501
19MTT1POrderableB7113Ridensport RebootB35663635908945Ridensport Reboot501
20MTT1POrderableB7114Ridensport RebootB35664635905645Ridensport Reboot484
21MTT1POrderableB7114Ridensport RebootB6066359035536Ridensport Reboot484
22MTT1POrderableB7114Ridensport RebootB600635908945Ridensport Reboot484
23MTT1POrderableB7114Ridensport RebootB600635908445Ridensport Reboot484
24MTT1POrderableB7114Ridensport RebootB35664635908945Ridensport Reboot484
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.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Update: So my code is fine
I was not made aware by my boss that two of our vendors are merging and they are migrating the part numbers over
So MTT is going to WM so WM has added columns. The price ended up being where the quantity was.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top