Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quotes Appearing

Status
Not open for further replies.

RandySS

Technical User
Dec 7, 2009
20
US
Hi Folks! I'm sure I'm overlooking an obviouse, but can't put my finger on why quote signs are appearing in the value stored at the below tag's address.

I want stored at Tag is: 12345
I'm getting stored at Tag is: "12345"

'***START***
Dim Tag
Dim VariableRow

VariableRow = 1

'Value entered into cell (1, 1) = 12345

Tag = Cells(VariableRow, 1).Value

'***END***

VB loads "12345" (with quotes) into variable Tag.
What method do I use if I can't have the quotes in my result?

Thanks much for your help!
 
VB loads "12345" (with quotes) into variable Tag.
It does? Where? How do you know this?
Code:
Sub Yadda()
Dim Tag
Dim VariableRow [COLOR=red]'  why is this not an explicit data type?[/color red]

VariableRow = 1

'Value entered into cell (1, 1) = 12345
Tag = Worksheets("Sheet1").Cells(VariableRow, 1).Value

' not here
MsgBox Tag

' not here either
Worksheets("Sheet1").Cells(1, 3).Value = Tag
End Sub

Gerry
 
Later in the program when I do a comparison such as:

If Tag = 1234 Then...

it fails. However, if I go back to my original code and change it from

Tag = Cells(VariableRow, 1).Value

to

Tag = 1234

the above comparison results in TRUE. Also, in the initial case, when hovering over the name of the variable (Tag) while troubleshooting the code, the mouse-over balloon shows "1234" whereas in the latter case (with Tag = 1234) it shows 1234 (no quotes) and the program executes sucessfully.

 
So, replace this:
Tag = Cells(VariableRow, 1).Value
with this:
Tag = Val(Cells(VariableRow, 1).Value)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
might also want to

Dim Tag as Long

or

Dim Tag as Integer


Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
I'll second Geoff (and Gerry), proper explicit variable declaration helps stop such variable type confusion and builds more robust code.

Andy
---------------------------------
Zebracorn: 50% Zebra, 50% Unicorn = 100% Real.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top