white space between names

  • Thread starter Thread starter hitmonkong
  • Start date Start date
H

hitmonkong

Dear All,

I am having trouble dealing with white space between names.

For example, I have the following code:
sheetName = "contact information"
Range("A2:D10") = sheetName

when running the above code, I get an error message "Name is invalid". If I
change the sheetName to something without a space in between, then the code
will run successfully. Is there a way to make Excel VBA recognize and not
fuss about the white space? I know in Access VBA, you can just put [] next to
the sheetName and it will take in the whole sheetName including the space.

Any help is appreciated.

Thank you.
 
Dear All,

I am having trouble dealing with white space between names.

For example, I have the following code:
sheetName = "contact information"
Range("A2:D10") = sheetName

when running the above code, I get an error message "Name is invalid". IfI
change the sheetName to something without a space in between, then the code
will run successfully. Is there a way to make Excel VBA recognize and not
fuss about the white space? I know in Access VBA, you can just put [] next to
the sheetName and it will take in the whole sheetName including the space..

Any help is appreciated.

Thank you.

you could define the strng and then use the "Split" functionality
and then reassign the variables as

dim Q
Q=Split(youstring," ")
'the " " denotes the delimeter as a space
Q=Q(1) & Q(2) 'puts the string together, note Q(0) may be your first
entry or Q(1) just proof it when you implement

basically, the easiest way is to take it apart and put it back
together.
 
It worked! Thank you so much.

jason said:
Dear All,

I am having trouble dealing with white space between names.

For example, I have the following code:
sheetName = "contact information"
Range("A2:D10") = sheetName

when running the above code, I get an error message "Name is invalid". If I
change the sheetName to something without a space in between, then the code
will run successfully. Is there a way to make Excel VBA recognize and not
fuss about the white space? I know in Access VBA, you can just put [] next to
the sheetName and it will take in the whole sheetName including the space..

Any help is appreciated.

Thank you.

you could define the strng and then use the "Split" functionality
and then reassign the variables as

dim Q
Q=Split(youstring," ")
'the " " denotes the delimeter as a space
Q=Q(1) & Q(2) 'puts the string together, note Q(0) may be your first
entry or Q(1) just proof it when you implement

basically, the easiest way is to take it apart and put it back
together.
 
Back
Top