Final space removed when moving to Object variable

  • Thread starter Thread starter groupie
  • Start date Start date
G

groupie

Is there a solution to this problem? The final space in a String is
deleted when assigned to a field in an Object variable.


Dim obHead As Object
Dim strLet As String

strLet = "ABCD " 'ABCD and a final space

obHead.Value("OBJ") = strLet "obHead.Value("OBJ") contains ABCD
(no space)


Thanks for any assistance!
 
Use the trim function

either
strLet = trim("ABCD ") 'ABCD and a final space

or
obHead.Value("OBJ") = trim(strLet) "obHead.Value("OBJ") contains ABCD
 
What object are you using?
What version of excel?

You may get more people to test if you share that info.
 
Yes,sorry should have been clearer.

I want to keep the final space from strLet in the object, notremoveit,
however the assignment to the object removes it.

Excel 2002 SP3

Seemsto happen to anything that is defined as an object.
 
Can you share one of the objects you used to see the problem?

Might as well test on one that doesn't work for you.
 
Ps.

I tried it with a commandbutton from the Control toolbox toolbar and this
returned 5:

Option Explicit
Sub testme()
Dim myObj As Object
Set myObj = ActiveSheet.CommandButton1
myObj.Caption = "qwer "
MsgBox Len(myObj.Caption)
End Sub
 
ps (again):

I used a combobox from the control toolbox toolbar and this returned 5, too.

Option Explicit
Sub testme()
Dim myObj As Object
Set myObj = ActiveSheet.ComboBox1
myObj.Value = "qwer "
MsgBox Len(myObj.Value)
End Sub

(This used .value)
 

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

Back
Top