Solved

weird textbox problem when clearing the textbox out

Posted on 2014-03-20
15
241 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
  • 7
  • 7
15 Comments
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
Can you upload a sample?
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
yes, Thanks the code for textbox on the userform.
0
 
LVL 3

Author Comment

by:fordraiders
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
I can't reproduce that behavior.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Please attach your workbook.
0
 
LVL 3

Author Comment

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


this seems to help
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
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 45

Accepted Solution

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

Author Comment

by:fordraiders
Comment Utility
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
Comment Utility
got me on the right track..
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
i spoke to soon.
my solution is still not solving problem
0
 
LVL 45

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now