Solved

weird textbox problem when clearing the textbox out

Posted on 2014-03-20
15
245 Views
Last Modified: 2014-03-21
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

0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
15 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39942478
Can you upload a sample?
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39942481
Is the code that you show in Userform2? If not is there another Textbox37 in the userform that contains the code?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39942540
yes, Thanks the code for textbox on the userform.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 3

Author Comment

by:fordraiders
ID: 39942569
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
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39942647
I can't reproduce that behavior.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39942672
Please attach your workbook.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39943324
If pTtyped = "" Then
pTtyped = Trim(UCase(UserForm2.TextBox37.Value))
Else
pTtyped = pTtyped
End If


this seems to help
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39943507
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
 
LVL 3

Author Comment

by:fordraiders
ID: 39943580
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
 
LVL 48

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39943584
TextBox37.Text = ""
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39943827
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
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39943830
got me on the right track..
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39943835
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
 
LVL 3

Author Comment

by:fordraiders
ID: 39944469
i spoke to soon.
my solution is still not solving problem
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39945458
Let me ask again. Can you attach the workbook?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question