Search For Upper or Lower Case Values

LikeButtah1

New Member
Joined
Apr 17, 2018
Messages
34
Here is the code I'm using to search for a Last Name and return the entire row of values into separate boxes on a user form. When I type the Last Name into the text box to search it must be with the Upper case first letter because if I don't capitalize the Last Name excel doesn't recognize it and nothing gets returned into the text boxes. Is there a way in vba to ignore whether or not the Last Name has a capitalized first letter. Thanks in advance.

Code:
Private Sub btnLName_Click()

                blnNew = False
                txtLastName.Text = ""
                txtFirstName.Text = ""
                txtC.Text = ""
                txtNewCard.Text = ""
                txtAccDes.Text = ""
                txtAccCreated.Text = ""
                txtAccGranted.Text = ""
                txtAccCancelled.Text = ""
                txtAccCategory.Text = ""
                txtNotes.Text = ""
   
    TRows = Worksheets("PNG Database").Range("A1").CurrentRegion.Rows.Count
    For i = 3 To TRows
        If Worksheets("PNG Database").Cells(i, 1).Value = TextBox1.Text Then
                
            txtLastName.Text = Worksheets("PNG Database").Cells(i, 1).Value
            txtFirstName.Text = Worksheets("PNG Database").Cells(i, 2).Value
            txtC.Text = Worksheets("PNG Database").Cells(i, 3).Value
            txtNewCard.Text = Worksheets("PNG Database").Cells(i, 4).Value
            txtAccDes.Text = Worksheets("PNG Database").Cells(i, 5).Value
            txtAccCreated.Text = Worksheets("PNG Database").Cells(i, 6).Value
            txtAccGranted.Text = Worksheets("PNG Database").Cells(i, 7).Value
            txtAccCancelled.Text = Worksheets("PNG Database").Cells(i, 8).Value
            txtAccCategory.Text = Worksheets("PNG Database").Cells(i, 9).Value
            txtNotes.Text = Worksheets("PNG Database").Cells(i, 12).Value
         
            Exit For
        End If
    Next i
    
   


End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
One method is to place this at the top of the code module.

Code:
Option Compare Text

This will make comparisons text-insensitive for the entire module.

Another method is to set the case of both strings being compared to either lower or upper case.

Code:
 If LCase(Worksheets("PNG Database").Cells(i, 1).Value) = LCase(TextBox1.Text) Then

The second method is more robust since it doesn't rely on the Option statement.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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