Comparing DICtionaries ( ͡° ͜ʖ ͡°)

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
781
Office Version
  1. 2016
Platform
  1. Windows
So i'm trying to check if a key from one dictionary exists in another, and if it does to write the value/keys to sheets depending on some if statements

Loop through all the keys from dicLIVE
if that key exists in dicQTY, the key contains "^4", and and the dicQTY value is greater than 8 then
write text, write the diceBay value associated with the key, and write 1

if that key exists in dicQTY, the key DOES NOT contains "^4", and and the dicQTY value is greater than 8 then
write text, write the diceBay value associated with the key, and write 4

if that key DOES NOT exist in dicQTY, or the dicQTY value is less than 8
write text. write the diceBay value associated with the key, and write text

else end if


so far i have
Code:
Sub oosNqty()
Dim oos As Worksheet
Dim qty As Worksheet
Dim ws As Worksheet
Dim x As Long, j As Long, i As Long


Set ws = Sheets("Description Helper")
Worksheets.Add After:=ws
Set oos = ActiveSheet
Worksheets.Add After:=ws
Set qty = ActiveSheet

x = 1
For Each Key In dicLIVE.Keys
x = x + 1

If dicQTY.exists(Key) And _
InStr(1, Key, "^4") > 0 And _
dicQTY(Key) >= 8 Then
    
    qty.Range("A" & x).Value = "Revise"
    qty.Range("B" & x).Value = dicLIVE(Key)
    qty.Range("C" & x).Value = 1
    
ElseIf dicQTY.exists(Key) And _
InStr(1, Key, "^4") = 0 And _
dicQTY(Key) >= 8 Then

    qty.Range("A" & x).Value = "Revise"
    qty.Range("B" & x).Value = dicLIVE(Key)
    qty.Range("C" & x).Value = 4
    
ElseIf not dicQTY.exists(Key) or _
dicQTY(Key) < 8 Then

    oos.Range("A" & x).Value = "End"
    oos.Range("B" & x).Value = dicLIVE(Key)
    oos.Range("C" & x).Value = "Incorrect"

Else
End If
Next



End Sub

to explain the dictionaries:
dicLIVE is live inventory. It consists of a part number and a listing number
dicQTY is the newest feed of inventory. It consists of a part number and a quantity

so if there is a listing that falls below 8 or no longer appears in the new inventory feed, it needs to be added to OOS

if the listing exists in the new inventory and is above 8 we need to write it to QTY. There are two kinds of part numbers that matter if a listing is live. One has "^4" and one does not.

its uhhhhhhhhhhhhhhh not working as intended, please help :biggrin:
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
actually this would work a lot better if i switched the listing number and part number in dicLIVE and got rid of the ^4
tl:dr the ^4 is a way to identify packages, but has the part number before it

so lets go with

Loop through all the keys from dicLIVE
if the value of that key exists in dicQTY,and and the dicQTY value is greater than 8 then
write text, and write the diceBay value associated with the key

if the value of that key exists DOES NOT exist in dicQTY, or the dicQTY value is less than 8
write text. write the diceBay value associated with the key, and write text

else end if

Code:
Sub oosNqty()
Dim oos As Worksheet
Dim qty As Worksheet
Dim ws As Worksheet
Dim x As Long, j As Long, i As Long


Set ws = Sheets("Description Helper")
Worksheets.Add After:=ws
Set oos = ActiveSheet
Worksheets.Add After:=ws
Set qty = ActiveSheet

x = 1
For Each Key In dicLIVE.Keys
x = x + 1

If dicQTY.exists(dicLIVE(Key)) And _
dicQTY(Key) >= 8 Then
    
    qty.Range("A" & x).Value = "Revise"
    qty.Range("B" & x).Value = dicLIVE(Key)
    
ElseIf not dicQTY.exists(dicLIVE(Key)) or _
dicQTY(Key) < 8 Then

    oos.Range("A" & x).Value = "End"
    oos.Range("B" & x).Value = dicLIVE(Key)
    oos.Range("C" & x).Value = "Incorrect"

Else
End If
Next



End Sub
 
Upvote 0
i got this working for me at the moment but i was wondering if there is a possible way to substitute the range.value for an array that prints to the sheet to increase the speed of the code.
i just don't know how i would set the length of an array to the length of a dictionary

Code:
Sub OOS()
Dim os As Worksheet
Dim key As Variant
Dim x As Long
Dim j As Long

Set os = Worksheets.Add(after:=Sheets(Sheets.count))
j = 1

MsgBox dicLIVE.count

For Each key In dicLIVE.items
    x = x + 1
If dicQTY.exists(key) And dicQTY(key) < 8 Then
    j = j + 1
    os.Range("B" & j).Value = dicLIVE.keys()(x - 1)
ElseIf Not dicQTY.exists(key) Then
    j = j + 1
    os.Range("B" & j).Value = dicLIVE.keys()(x - 1)
Else
End If
Next key



End Sub
 
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