Using inputbox to check dictionary

BlakeSkate

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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
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
 

BlakeSkate

Well-known Member
Joined
Jan 26, 2015
Messages
613
Office Version
2016
Platform
Windows
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
Try replacing Val with CLng
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,082,316
Messages
5,364,505
Members
400,803
Latest member
Niyetkhan

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top