Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Inability to add quotation mark around a variable by concatenation in VBA

Hi,

I am outputting some data for another programmer to parse.

He has requested that I add quotation marks around each variable, but when I attempt to do it VBA will have none of it, and wants me to insert 2 quotation marks or none!

Here's my code:

Dim bCount As Byte
For bBandNo = 1 To 9

If arrbBandValue(bBandNo) 0 Then

bCount = bCount + 1
'Last one needs special treatment (no comma after and quotes at the end
If bCount = bBandCount Then

sBandValues = sBandValues & arrbBandValue(bBandNo) & ";" & bBandNo
Exit For

End If

sBandValues = sBandValues & arrbBandValue(bBandNo) & ";" & bBandNo & ","

End If

Next bBandNo

psBandValues = sBandValues


I tried two approaches the first being to add them at the end which would be easiest. I just amended the last line:

psBandValues = """ & sBandValues & """

However this destroys my variable returning instead of "MyVariableString" as I intend, instead it returns

The second to do it 'at source' which yielded the same result.

Maybe I am missing something (probably) but should it be so hard to simply add quotation marks around a variable???

Any help much appreciated, M.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Inability to add quotation mark around a variable by concatenation in VBA

Try...

psBandValues = Chr(34) & sBandValues & Chr(34)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Inability to add quotation mark around a variable byconcatenation in VBA

On Wednesday, April 9, 2014 10:40:37 AM UTC+8, Mark Stephens wrote:
Hi,



I am outputting some data for another programmer to parse.



He has requested that I add quotation marks around each variable, but when I attempt to do it VBA will have none of it, and wants me to insert 2 quotation marks or none!



Here's my code:



Dim bCount As Byte

For bBandNo = 1 To 9



If arrbBandValue(bBandNo) 0 Then



bCount = bCount + 1

'Last one needs special treatment (no comma after and quotes at the end

If bCount = bBandCount Then



sBandValues = sBandValues & arrbBandValue(bBandNo) & ";" & bBandNo

Exit For



End If



sBandValues = sBandValues & arrbBandValue(bBandNo) & ";" & bBandNo & ","



End If



Next bBandNo



psBandValues = sBandValues





I tried two approaches the first being to add them at the end which would be easiest. I just amended the last line:



psBandValues = """ & sBandValues & """



However this destroys my variable returning instead of "MyVariableString" as I intend, instead it returns



The second to do it 'at source' which yielded the same result.



Maybe I am missing something (probably) but should it be so hard to simply add quotation marks around a variable???



Any help much appreciated, M.


Hey Garry, that worked like a dream thanks so much for the help, M.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Inability to add quotation mark around a variable by concatenation in VBA

Hey Garry, that worked like a dream thanks so much for the help, M.

Glad to help...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Inability to add quotation mark around a variable by concatenationin VBA

On 09/04/2014 03:40, Mark Stephens wrote:
Hi,

I am outputting some data for another programmer to parse.

He has requested that I add quotation marks around each variable, but when I attempt to do it VBA will have none of it, and wants me to insert 2 quotation marks or none!

Here's my code:

Dim bCount As Byte
For bBandNo = 1 To 9

If arrbBandValue(bBandNo) 0 Then

bCount = bCount + 1
'Last one needs special treatment (no comma after and quotes at the end
If bCount = bBandCount Then

sBandValues = sBandValues & arrbBandValue(bBandNo) & ";" & bBandNo
Exit For

End If

sBandValues = sBandValues & arrbBandValue(bBandNo) & ";" & bBandNo & ","

End If

Next bBandNo

psBandValues = sBandValues


I tried two approaches the first being to add them at the end which would be easiest. I just amended the last line:

psBandValues = """ & sBandValues & """

However this destroys my variable returning instead of "MyVariableString" as I intend, instead it returns

The second to do it 'at source' which yielded the same result.

Maybe I am missing something (probably) but should it be so hard to simply add quotation marks around a variable???


It isn't but you have to escape them in. So to add one " you need two.

"""" = " as a string

So

a = """" & "test" & """"
debug.print a

will print "test"

Any help much appreciated, M.



--
Regards,
Martin Brown
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
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 1 November 29th 08 07:49 AM
Single Quotation mark in CSV hon123456 Excel Discussion (Misc queries) 0 November 29th 08 05:15 AM
excel save as csv quotation mark Briankwei1234567 Excel Programming 1 August 2nd 07 09:48 PM
how do I concatenate text that has a quotation mark sparkroms Excel Discussion (Misc queries) 2 July 8th 05 09:20 PM
chr() for quotation mark Todd Huttenstine Excel Programming 7 July 29th 04 08:14 PM


All times are GMT +1. The time now is 10:56 PM.

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

About Us

"It's about Microsoft Excel"