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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting quote marks around existing cell values

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
Someone gave me this script but I have yet to figure out what the first quote mark is for. I can read and understand this script, but I cannot figure out why there are a total of 3 single quote marks seemingly being inserted by this line:

curntcell.Value = "'" & "'" & curntcell.Value & "'"

...but it works perfectly and the cell contents suddenly have single quotes around them after running this script. What's that extra single quote mark for in the script? Thanks.

SCRIPT:

Sub quotes()
Dim curntcell As Object
For Each curntcell In Selection
curntcell.Value = "'" & "'" & curntcell.Value & "'"
Next curntcell

End Sub
 
Hi,

If you enter only one single quote before entering your real data then excel cell will see that you are entering a "text" by ignoring the real data type.

So if you enter '1255 in a cell then excell will see that you are entering 1255 as string and remove ' from the beginning while it is viewing it in cell and as data.

So if code was

curntcell.Value = "'" & curntcell.Value & "'"

Then it wouldn't be like you need, in quotes I mean. It will be ;

1255'

after code is done.

Second single quote at the beginning tells Excel that it is entering single quote, not a sign for Excel to tell it to recognize it as string. So it becomes :

'1255'

after code, how you need..

Is it complicated with my description ?

:)

Oz
 
Nope, the explanation of the first quote tells me exactly what I didn't know. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top