# Excel query question

I have written an excel function like below:
="WHEN mynumber >= '" & D65 & "' AND mynumber <= '" & E65 & "' THEN '" & A65 & " " & B65 & " " & C65 & "'"

The above mostly works the way I want. But if there value of C33 is null, it ends in an empty blank character at the end of the calculated value.
Could you suggest how I could get rid of the empty character. I trid TRIM function but could not make that work.

Thanks a lot.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
* You could use my Better Concatenate function.
http:A_7811-A-Better-Concatenate-Function.html

* You will probably need to use an IF() function to check the existence of a cell and only prepend the space character if there is something to concatenate.

* If C33 is the only cell that might be empty, you could Trim the result.
``````="WHEN mynumber BETWEEN '" & D33 & "' AND '" & E33 & "' THEN '" & Trim(A33 & " " & B33 & " " & C33 & "'")
``````
0
Author Commented:
Thank you. I will look into the Better Concatenate function. But for now I tried:
="WHEN mynumber BETWEEN '" & D33 & "' AND '" & E33 & "' THEN '" & Trim(A33 & " " & B33 & " " & C33 & "'")
But this did not eliminate the last character coming out of null E33 value.
0
Commented:
Trim each of those cells as well.
``````="WHEN mynumber BETWEEN '" & Trim(D33) & "' AND '" & Trim(E33) & "' THEN '" & Trim(A33 & " " & B33 & " " & C33 & "'")
``````
0
Author Commented:
Thank you. But sorry this does not remove the last blank space "before" the ' character (single quote character) at the end.
Because the Trim(A33 & " " & B33 & " " & C33 & "'") is not trimming before the ' character.
I tried to modify the above to bring the 1st bracket before the ' character but I get syntax error.
0
Commented:
Sorry.  Misplaced parenthesis for that original Trim function.
``````="WHEN mynumber BETWEEN '" & Trim(D33) & "' AND '" & Trim(E33) & "' THEN '" & Trim(A33 & " " & B33 & " " & C33) & "'"
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Works! Many thanks!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.