mike637
asked on
Excel VBA Highlight text in textbox
Hello Experts,
I have 2 issues to resolve.
I have a UserForm that is initialized. I want the userform to show then go to textbox1 and highlight the text for editing. (The cursor defaults to the end of the text). I have that textbox populate from another worksheet.range but I want to set focus and highlight for easy editing.
Then next issue is that I have another text box on the same UserForm that populates from another worksheet.range and must be a numeric value. I am using a Public Function IntegerValidation(ByVal MyTextBox As Control) to check it's contents - This works fine, but I want it to highlight the text.value to easily edit it correctly if the enduser enters a non-numeric value.
Thanks
I have 2 issues to resolve.
I have a UserForm that is initialized. I want the userform to show then go to textbox1 and highlight the text for editing. (The cursor defaults to the end of the text). I have that textbox populate from another worksheet.range but I want to set focus and highlight for easy editing.
Then next issue is that I have another text box on the same UserForm that populates from another worksheet.range and must be a numeric value. I am using a Public Function IntegerValidation(ByVal MyTextBox As Control) to check it's contents - This works fine, but I want it to highlight the text.value to easily edit it correctly if the enduser enters a non-numeric value.
Thanks
ASKER
Experts,
Here is the code I have in my UserForm, but it is not setting focus or highlighting the text for editing in the TextBox1 named Manager1 when the UserForm is initialized. What am I doing wrong???
I am using Sheets 3 - 12 for the UserForm and have the data on Sheet1
Private Sub UserForm_Initialize()
Manager1.Text = Sheet1.Range("A20")
With Manager1
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Here is the code I have in my UserForm, but it is not setting focus or highlighting the text for editing in the TextBox1 named Manager1 when the UserForm is initialized. What am I doing wrong???
I am using Sheets 3 - 12 for the UserForm and have the data on Sheet1
Private Sub UserForm_Initialize()
Manager1.Text = Sheet1.Range("A20")
With Manager1
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Can I see your file?
Sid
Sid
ASKER
As requested.
2011-Weekly-Call-In.xls
2011-Weekly-Call-In.xls
ASKER
I saw that too. However, when I go to the other worksheets - I do not always get the same result.
It is sort of hit or miss.
mike637
Which worksheet you don't see it in?
Sid
Sid
I checked every worksheet and it is working just fine.
Sid
Sid
ASKER
I guess I am missing something. When I go to February or any other month - it is not highlighted.
Did you close the workbook - reopen and try each worsheet??
Very confused.
Yes I did :)
Sid
Sid
Posting video in a moment.
Sid
Sid
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
I added Unload me on exit and then each time I opened it, it loaded fine.
Thanks again!!
I added Unload me on exit and then each time I opened it, it loaded fine.
Thanks again!!
Sid
Code Used
Open in new window
Textbox-Sample.xls