problem writing capital letter into textbox on userform when search

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
hi

I face problem when write the letters based on COL A the second letter always write small letter .

what I want when search data like AA then should show only data for relating of AA and when writing capital letter not convert to small.
this is the code
VBA Code:
Private Sub TextBox1_Change()
Me.TextBox1 = StrConv(Me.TextBox1.Text, vbProperCase)
Me.ListBox1.Clear
ListBox1.ColumnCount = 5
For i = 2 To Application.WorksheetFunction.CountA(sheet1.Range("A:A"))
a = Len(Me.TextBox1.Text)
If LCase(Left(sheet1.Cells(i, 1).Value, a)) = LCase(Left(Me.TextBox1.Text, a)) Then
Me.ListBox1.AddItem sheet1.Cells(i, "A").Value
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = sheet1.Cells(i, "B").Value
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = sheet1.Cells(i, "C").Value
Me.ListBox1.List(ListBox1.ListCount - 1, 3) = sheet1.Cells(i, "D").Value
Me.ListBox1.List(ListBox1.ListCount - 1, 4) = sheet1.Cells(i, "E").Value
End If
Next
End Sub

1.JPG

any suggestion to fix it ,please?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If you don't want the letters converted to lower case, remove this line
VBA Code:
Me.TextBox1 = StrConv(Me.TextBox1.Text, vbProperCase)
 
Upvote 0
thanks but how should mod the code when search specific item . it should just show what I search but the problem as the picture . it also bring any item contains letter A when write the first letter . I would when finish writing . it should only show AA
 
Upvote 0
If you only want exact matches change this line
VBA Code:
If LCase(Left(sheet1.Cells(i, 1).Value, a)) = LCase(Left(Me.TextBox1.Text, a)) Then
to
VBA Code:
If Sheet1.Cells(i, 1).Value = Me.TextBox1.Text Then
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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