Adding quotes around text, i.e. "text"

T

tom

Why can I not get this to work? I want to add quotes around text in a
range, using the following routine:

--------------
Sub addQuotes()

Dim cell As Range
Dim contents As String
Dim quotes As String

quotes = ""

For Each cell In Range("a1:aw1")
If IsEmpty(cell.Text) = False Then
contents = cell.Text
cell.Value = quotes & contents & quotes
End If
Next cell

End Sub
----------------

But the quotes don't show up. If the variable quotes is """" then I
get double quotes around the text.

What is a better way to approach this?

Thanks for your help.

-tom
 
N

Norman Jones

Hi Tom,

Try this modification:

'--------------
Sub addQuotes2()

Dim cell As Range
Dim contents As String
Dim quotes As String

quotes = """" '<<=== Quotes need to be doubled!

For Each cell In Range("a1:aw1")
If IsEmpty(cell.Value) = False Then '<<== Cell.Text ==> Cell.Value
contents = cell.Value
cell.Value = quotes & contents & quotes
End If
Next cell

End Sub
 
T

tom

Why do you want to do that. If it is so you can export your file with text
enclosed with quotes, using this approach will result in
""text"",

Thanks Tom - that was exactly what I needed.
Thanks to the others who posted - given what I told you, you answered
perfectly. A more complete message on my part would have no doubt
helped.

-tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top