Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default WHAT's THE RULE?: Use of apostrophes(" ")


Can someone come up with a golden rule governing the use of apostrophe
(" ") in writing out text in VBA? For example:

1. Msgbox "Enter value as ""Number"" of Apples" ----produces
<Enter value as "Number" of apples
I don't have much problem with the convention here but see:


2. Range("a1") = "=INDIRECT("""& Range("b2") & """)" --- produces

=INDIRECT("Sheet5!") in Cell A1 of the activesheet (assuming Cell b
contains the string SHEET5!

One would imagine that following (1), the use of Double rather tha
Treble null strings as in *Range("a1") = "=INDIRECT(""& Range("b2")
"")"* should work. What gives?

I need a handle to guide me in the correct usage of apostrophes in har
cases like this and not resort to hit-and-miss, trial-and-erro
approaches.


Thanks for any illumination

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=46908

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default WHAT's THE RULE?: Use of apostrophes(" ")

When you are using strings, you need one to tell VBA it is text, then two
for every embedded apostrophe, so that VBA does not think you are closing
the text.

Think about it, and strip out the words and add spaces

Msgbox "Enter value as ""Number"" of Apples" becomes
Msgbox " "" ....."" "

Range("a1") = "=INDIRECT("""& Range("b2") & """)" becomes
Range("a1") = "=INDIRECT("" " & Range("b2") & " "" "

it is pretty consistent

--
HTH

Bob Phillips

"davidm" wrote in
message ...

Can someone come up with a golden rule governing the use of apostrophes
(" ") in writing out text in VBA? For example:

1. Msgbox "Enter value as ""Number"" of Apples" ----produces
<Enter value as "Number" of apples
I don't have much problem with the convention here but see:


2. Range("a1") = "=INDIRECT("""& Range("b2") & """)" --- produces

=INDIRECT("Sheet5!") in Cell A1 of the activesheet (assuming Cell b2
contains the string SHEET5!

One would imagine that following (1), the use of Double rather than
Treble null strings as in *Range("a1") = "=INDIRECT(""& Range("b2") &
"")"* should work. What gives?

I need a handle to guide me in the correct usage of apostrophes in hard
cases like this and not resort to hit-and-miss, trial-and-error
approaches.


Thanks for any illumination.


--
davidm
------------------------------------------------------------------------
davidm's Profile:

http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=469086



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default WHAT's THE RULE?: Use of apostrophes(" ")

it is pretty consistent

strange, I always use try and error :)

write 1 into B1 and hello into B2. The result should be

1"hello"

the formula is
=B1&""""&B2&""""

does this fit to your rule?

arno
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default WHAT's THE RULE?: Use of apostrophes(" ")

Yes.one to indicate text, 2 to add a quote, one to end text.

=B1&" "" "&B2&" "" "

--
HTH

Bob Phillips

"arno" wrote in message
...
it is pretty consistent


strange, I always use try and error :)

write 1 into B1 and hello into B2. The result should be

1"hello"

the formula is
=B1&""""&B2&""""

does this fit to your rule?

arno



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default WHAT's THE RULE?: Use of apostrophes(" ")


Many thanks Bob.


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=469086



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default WHAT's THE RULE?: Use of apostrophes(" ")

Yes.one to indicate text, 2 to add a quote, one to end text.
cool. thank you.
arno
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
how to SAVE new "formatting rule(s)"? jope Excel Discussion (Misc queries) 0 April 29th 08 10:15 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 02:58 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"