-
Feb 24th, 2012, 11:13 AM
#1
Thread Starter
New Member
Difficulty adding quotes around a variable in an excel formula
I have a data retrieval function, which works through an excel plug in. For Example, call it ItemValue. This Function is supposed to retrieve data based on the alphanumeric ID number, entered as a string in the first argument, and the data type entered into the second argument.(Such as "Value", "Units", etc.)
When creating the formula, it uses a value from an entry box in a form I created, variable name IDnum1. When running the formula without quotes over this variable as below, I get no errors.
Cells(1, 2).Formula = "=ItemValue(" & IDnum1.Value & ", ""Units"")"
(say for instance IDnum1.Value = Item25)
Output being -> =ItemValue(Item25, "Units")
However i need Quotes over the "Item25" for the function to work properly. From my understanding, I just need to add double quotes on each side of the variable for quotes to appear. However, when I do this, typed as shown below. I get a Type Mismatch Error.
Cells(1, 2).Formula = "=ItemValue(""" & IDnum1.Value & """, ""Units"")"
When Debugging that string.
For ex: Debug.Print "=ItemValue(""" & IDnum1.Value & """, ""Units"")"
I get the output that I am looking for.
Does anyone know why I am getting this error?
Any help would be greatly appreciated.
Thanks in advance!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|