white space between names

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.
 
J

jason

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.
 
H

hitmonkong

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top