Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Insert " " into a string

I am inserting formulas into cells using a macro. Several formulas require a
blank. (" ")

Ex1: Sheets("Frame 6").Range("G3").Value = "=IF(ISERROR(VLOOKUP(A3," &
CSpath & ",29,FALSE))," ",VLOOKUP(A3," & CSpath & ",29,FALSE))"

Ex2: Sheets("Frame 6").Range("F3").Value = "=IF(D3=1,VLOOKUP(A3," & CSpath &
",34,FALSE)," ")"

However, Excel won't let you do this. How can I get the blanks in there?
Thanks in advance.

-Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Insert " " into a string

Try:-

Double double quotes for the spaces i.e. "" ""

Mike

"CWillis" wrote:

I am inserting formulas into cells using a macro. Several formulas require a
blank. (" ")

Ex1: Sheets("Frame 6").Range("G3").Value = "=IF(ISERROR(VLOOKUP(A3," &
CSpath & ",29,FALSE))," ",VLOOKUP(A3," & CSpath & ",29,FALSE))"

Ex2: Sheets("Frame 6").Range("F3").Value = "=IF(D3=1,VLOOKUP(A3," & CSpath &
",34,FALSE)," ")"

However, Excel won't let you do this. How can I get the blanks in there?
Thanks in advance.

-Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Insert " " into a string

I already tried that. Worked this time though. Thanks.

"Mike H" wrote:

Try:-

Double double quotes for the spaces i.e. "" ""

Mike

"CWillis" wrote:

I am inserting formulas into cells using a macro. Several formulas require a
blank. (" ")

Ex1: Sheets("Frame 6").Range("G3").Value = "=IF(ISERROR(VLOOKUP(A3," &
CSpath & ",29,FALSE))," ",VLOOKUP(A3," & CSpath & ",29,FALSE))"

Ex2: Sheets("Frame 6").Range("F3").Value = "=IF(D3=1,VLOOKUP(A3," & CSpath &
",34,FALSE)," ")"

However, Excel won't let you do this. How can I get the blanks in there?
Thanks in advance.

-Chris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Insert " " into a string

I am inserting formulas into cells using a macro. Several formulas require
a
blank. (" ")

Ex1: Sheets("Frame 6").Range("G3").Value = "=IF(ISERROR(VLOOKUP(A3," &
CSpath & ",29,FALSE))," ",VLOOKUP(A3," & CSpath & ",29,FALSE))"

Ex2: Sheets("Frame 6").Range("F3").Value = "=IF(D3=1,VLOOKUP(A3," & CSpath
&
",34,FALSE)," ")"

However, Excel won't let you do this. How can I get the blanks in there?
Thanks in advance.


Because VBA uses quote marks to delineate String constants, you can't just
use them as is inside of a String constant in order to include them within
that String constant. If you double them up, however, VBA will treat the
doubled up quote marks as if they were a single included quote mark. Here is
your first example modified to account for this...

Sheets("Frame 6").Range("G3").Value = "=IF(ISERROR(VLOOKUP(A3," & CSpath &
",29,FALSE)),"" "",VLOOKUP(A3," & CSpath & ",29,FALSE))"

Notice that your " " has become "" "".

Rick

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Insert " " into a string

You can also use Chr() to insert spaces:

Sub MakeSpace
Range("A1").Value = "Make" & Chr(32) & "space"
Range("A2").Value = "Make" & Chr(vbKeySpace) & "space"
End Sub

vbKeySpace is the VBA constant for the Space key.

Mark Lincoln

On Jun 12, 9:16 am, CWillis wrote:
I am inserting formulas into cells using a macro. Several formulas require a
blank. (" ")

Ex1: Sheets("Frame 6").Range("G3").Value = "=IF(ISERROR(VLOOKUP(A3," &
CSpath & ",29,FALSE))," ",VLOOKUP(A3," & CSpath & ",29,FALSE))"

Ex2: Sheets("Frame 6").Range("F3").Value = "=IF(D3=1,VLOOKUP(A3," & CSpath &
",34,FALSE)," ")"

However, Excel won't let you do this. How can I get the blanks in there?
Thanks in advance.

-Chris





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Insert " " into a string

On Tue, 12 Jun 2007 06:16:00 -0700, CWillis
wrote:

I am inserting formulas into cells using a macro. Several formulas require a
blank. (" ")


Others have posted the solution. However, a word of caution. With your " "
you are NOT inserting a "blank", rather you are inserting a <space character.

If you want to insert a null string, which is generally what is meant when
someone writes about inserting a blank, you should not include the <space.

So instead of "" "" you should be using """"
--ron
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
Converting "uppercase" string data to "lower case" in CSV file [email protected] Excel Discussion (Misc queries) 2 August 12th 08 08:36 PM
Lost "File Menu" - now it's "Edit / View / Insert.." but no "F daves Excel Discussion (Misc queries) 3 April 24th 07 04:52 AM
insert "-" as fourth character in number string cursednomore Excel Discussion (Misc queries) 2 February 7th 07 07:33 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
Macro to insert "0" in front of 4 character string Lowell B. Copeland[_2_] Excel Programming 2 August 29th 03 03:43 PM


All times are GMT +1. The time now is 02:44 PM.

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"