weird textbox problem when clearing the textbox out

excel vba userform   textbox

In the change event of the textbox.

If someone highlights the textbox contents  and then copies and pastes things into the textbox..the textbox seems to just keep the old values in and gets jumbled with alot of spaces.

Private Sub TextBox37_Change()
'Dim t As String
't = UCase(UserForm2.TextBox37.Text)
'UserForm2.TextBox37.Text = t
 
 UserForm2.TextBox37.Text = UCase(TextBox37.Text)


End Sub


What I need: sone clean of of making sure extra spaces and wahtever was there before gets cleaned out before typing or copy and pasting new values into the textbox ?

Thanks
fordraiders

Open in new window

LVL 3
FordraidersAsked:
Who is Participating?
 
Martin LissConnect With a Mentor Older than dirtCommented:
TextBox37.Text = ""
0
 
MacroShadowCommented:
Can you upload a sample?
0
 
Martin LissOlder than dirtCommented:
Is the code that you show in Userform2? If not is there another Textbox37 in the userform that contains the code?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
FordraidersAuthor Commented:
yes, Thanks the code for textbox on the userform.
0
 
FordraidersAuthor Commented:
if somone types in SV29113...and then copies another value from the sheet..goes back to the text box and highlights the text in the textbox and thinks they are deleting it....then paste the new value..it keeps padding copy after copy sometimes.
so if i copy a new value...like sc435.

The textbox then contains   SV29113 SC435
0
 
Martin LissOlder than dirtCommented:
I can't reproduce that behavior.
0
 
Martin LissOlder than dirtCommented:
Please attach your workbook.
0
 
FordraidersAuthor Commented:
If pTtyped = "" Then
pTtyped = Trim(UCase(UserForm2.TextBox37.Value))
Else
pTtyped = pTtyped
End If


this seems to help
0
 
Martin LissOlder than dirtCommented:
There's probably something else going on. Are there any other references in the code that update TextBox37? Other than that I can't help any more unless you can attach the workbook.
0
 
FordraidersAuthor Commented:
no other references.

but, let me ask this then.

What is a proper statement to totally clear a textbox full of any characters.

textbox37.clear ?

TextBox37.Value = ""   ?
TextBox37.Text  =  ""  ?

Thanks
fordraiders
0
 
FordraidersAuthor Commented:
this finally did it...


' this piece of code will get rid of the extra blank cell
With TextBox37
  If .SelStart Then
    .SelStart = .SelStart - 1
    .SelLength = 1
    .SelText = ""
  End If
' .SetFocus
End With
0
 
FordraidersAuthor Commented:
got me on the right track..
0
 
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2013
0
 
FordraidersAuthor Commented:
i spoke to soon.
my solution is still not solving problem
0
 
Martin LissOlder than dirtCommented:
Let me ask again. Can you attach the workbook?
0
All Courses

From novice to tech pro — start learning today.