Removal of spaces

  • Thread starter Thread starter Neil
  • Start date Start date
N

Neil

I have some code that gets the value from a couple of
combo boxes and strings it together using "&" and then
places it in a text box. I want to be able to examine
this text, look for any spaces and remove them before
placing it in the text box. How can i do this?
 
Neil,

You can use "replace".
Please change "a b c" to the variable that you are using.


Code:
 
Use Trim, Rtrim or Ltrim to remove leading and trailing spaces from a text
string
eg
mystring = " this is some text "

remove leading spaces with
mynewstring = Ltrim(mystring)

remove trailing spaces with
mynewstring = Rtrim(mystring)

remove both leading and trailing
mynewstring = Trim(mystring)

Do this before you concatenate your strings with &

mynewstring = Trim(string1) & Trim(string2) & Trim(string3)

Cheers
Nigel
 
Neil,

Sub testit()
Dim strMyValue As String

strMyValue = "T h e A b y s s"
ComboBox1.AddItem Replace(strMyValue, " ", "")
End Sub

Rob
 
Replace was added in Excel 2000, so if you will use the code in an earlier
version

sStr = Application.Substitute(sStr," ","")
 
Back
Top