VBA case insentitive look up parameters

GedSalter

Board Regular
Joined
Apr 24, 2019
Messages
80
I have the following code. It works perfectly if I type in the correct case sensitivity. Is there a way to make the search case insenitive? I would also like to either search for first name or surname. Do I need to separate macros or can it be done with one?


VBA Code:
Private Sub CommandButton2_Click()

Dim Firstname As String
Firstname = Trim(txtFirstname.Text)
Lastrow = Worksheets("Portal").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To Lastrow

If Worksheets("Portal").Cells(i, 2).Value = Firstname Then
TxtSurname.Text = Worksheets("Portal").Cells(i, 3).Value
TxtDOB.Text = Worksheets("Portal").Cells(i, 4).Value
Gender.Text = Worksheets("Portal").Cells(i, 5).Value
Number.Text = Worksheets("Portal").Cells(i, 1).Value
Age.Text = Worksheets("Portal").Cells(i, 12).Value
MemberSince.Text = Worksheets("Portal").Cells(i, 8).Value
Years.Text = Worksheets("Portal").Cells(i, 13).Value
Status.Text = Worksheets("Portal").Cells(i, 14).Value
Membership.Text = Worksheets("Portal").Cells(i, 6).Value
FEESpaid.Text = Worksheets("Portal").Cells(i, 7).Value
PaidDate.Text = Worksheets("Portal").Cells(i, 9).Value

End If
Next


End Sub




Thanks in advance to any and all who help


regards

Ged
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
The simplest way would be to change your If..Then statement to this...
Rich (BB code):
If LCase(Worksheets("Portal").Cells(i, 2).Value) = LCase(Firstname) Then
 
Upvote 0
Solution
The simplest way would be to change your If..Then statement to this...
Rich (BB code):
If LCase(Worksheets("Portal").Cells(i, 2).Value) = LCase(Firstname) Then
that works great. if I do a partial search and come up with several possible answers is it capable of achieving that?

Can I also search using surname function in the same VBA or do I require another one. How would this fit in?

regards

Ged
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,890
Members
449,477
Latest member
panjongshing

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