Using inputbox to check dictionary

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
781
Office Version
  1. 2016
Platform
  1. Windows
Code:
Sub findQTY()
Dim pnum As Variant

pnum = InputBox("Please Type in the part number")
If dicQTY.exists(pnum) Then
MsgBox dicQTY(pnum)
Else
MsgBox "No quantity available for this part number"
End If
End Sub

the objective is to have the user enter a part number and it will either return the quantity or display an error where the part number does not exist within the dictionary

the problem occurs when pnum is all numeric.
so something that SHOULD exist in the dictionary is
"80017" with a value of 22
It returns the "No quantity" message though.

whereas "FK3264" with a value of 7 will display the correct msgbox because its a string?
any help would be appreciated
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try
Code:
pnum = InputBox("Please Type in the part number")
[COLOR=#ff0000]If IsNumeric(pnum) Then pnum = Val(pnum)[/COLOR]
If dicQTY.exists(pnum) Then
 
Upvote 0
Val(pnum)

seems to convert pnum to a double?
is there a version of this syntax for long and int?

edit:
oh yeah it works perfectly by the way
 
Last edited:
Upvote 0
Try replacing Val with CLng
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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