problem writing capital letter into textbox on userform when search

Alaa mg

Board Regular
Joined
May 29, 2021
Messages
137
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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
If you don't want the letters converted to lower case, remove this line
VBA Code:
Me.TextBox1 = StrConv(Me.TextBox1.Text, vbProperCase)
 

Alaa mg

Board Regular
Joined
May 29, 2021
Messages
137
Office Version
  1. 2019
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,728
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,147,734
Messages
5,742,865
Members
423,760
Latest member
photogfrog

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
Top