Dynamic check Textboxes for Ucase

7thwave

New Member
Joined
Mar 23, 2018
Messages
4
Excellists,

I've constructed a userform te perform a textsearch for some keywords. I want to check the textbox input for Ucase. I can do that one by one as follows:

Code:
Private Sub TextBox1_Change()
'If TextBox1.Text <> LCase(TextBox1.Text) Then
'MsgBox "Geen hoofdletters!!"
'TextBox1 = ""
'TextBox1.SetFocus
'End If
End Sub

As there are 8 boxes i would like to do it dynamiccaly. But my effords fail. See coding below. Where do i go wrong?

Code:
Private Sub InputTextBox_change()
Dim x As Integer
For x = 1 To 8
If Me.Controls("textbox" & x) = UCase("textbox" & x) Then
MsgBox "Geen hoofdletters!!"
Me.Controls("textbox" & x).Value = ""
End If
Next x
End Sub

Is it me or is it not possible to upload examplefile???

Regards,

Luc
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Luc

Couldn't you allow the user to enter lower/upper case in the textbox(es) and then convert to the case you want when the exit?
 
Upvote 0
Hi Norie,

Well why not? whatever works. I've set my program to change the targettext to LCase; so in the combi it should work. Do you have a tip on how to change the textbox strings to LCase? I possible all eight?

Thank you in advance.

Luc
 
Upvote 0
Luc

Do you mean have code that could handle multiple textboxes rather than having individual code for each textbox?
 
Upvote 0
Nori,

Yes. I already took you advise and changed the coding for textboxes one by one. Works already, so thank you for the tip. As i am just starting with VBA i'm eager to learn :) and my early attempts consist of a lot of those recurring peaces of code. So, if you don't mind showing me how to handle multiple textboxes (or whatever) i would be gratefull.

Thanks already!!

Code:
 If TextBox1.Text <> "" Then
        If InStr(cell, LCase(TextBox1.Text)) <> 0 Then i = i + 1
        cell.Offset(0, 2) = UBound(Split(cell, LCase(TextBox1.Text)))
    End If
    
    If TextBox2.Text <> "" Then
        If InStr(cell, LCase(TextBox2.Text)) <> 0 Then i = i + 1
        cell.Offset(0, 3) = UBound(Split(cell, LCase(TextBox2.Text)))
    End If
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top