Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Adding quotes around text, i.e. "text"

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Adding quotes around text, i.e. "text"

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


---
Regards,
Norman



"tom" wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Adding quotes around text, i.e. "text"

Tom-

Try

quotes = chr(34)

HTH

Matt


"tom" wrote in message
oups.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Adding quotes around text, i.e. "text"

Replace this:
quotes = ""

With this:
quotes = """"

"tom" wrote:

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding quotes around text, i.e. "text"

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"",
rather than

"text",

If that is what you are doing, look at:

http://support.microsoft.com/default...b;en-us;291296
Procedure to export a text file with both comma and quote delimiters in
Excel

--
Regards,
Tom Ogilvy

"tom" wrote in message
oups.com...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Adding quotes around text, i.e. "text"

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formating numbers &"Text" to appear as currency &"Text" in formula Robin K. Excel Discussion (Misc queries) 6 May 7th 07 02:03 PM
"formula is too long" AND test for whether double-quotes are next-to text or number?? The Moose Excel Discussion (Misc queries) 2 September 14th 06 05:29 AM
Saving as Text (tab delimited) surrounds text with "quotes" Mike521 Excel Discussion (Misc queries) 2 June 8th 06 02:28 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM
I need to put text in quotes(") Donna[_7_] Excel Programming 3 February 22nd 05 01:45 PM


All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"