VBA: How to find a match that NOT Case-sensitive?

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
I have a list of Usernames in column K. When a user opens the workbook I have code that checks that list, and if the current user ( Using Environ(Username)), isn't on the list it adds the user to the end of the list. If the username is already in the list it does nothing. It works great, but it seems like Windows doesn't care about the case sensitivity of the username when logging onto the computer, so Excel sees the same username differently depending on the upper and lower cases used to log in. For example: jsmith1 and JSmith1 should be the same, but excel sees them differently. How do I amend this code to use wildcards?

Code:
With Sheets("Sheet2")
    For r = 1 To lastrow + 1
        If .Cells(r, 11).Value = Environ("Username") Then
            Exit For
        ElseIf .Cells(r, 11).Value = "" Then
        ThisWorkbook.Sheets("Sheet2").Cells(lastrow + 1, 11) = Environ("Username")
        ThisWorkbook.Sheets("Sheet2").Cells(lastrow + 1, 12) = Format(Now, "mm/dd/yy hh:mm")
        End If
    Next r
End With
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi, one way would be to convert both values to the same case, for example:

Rich (BB code):
If UCase(.Cells(r, 11).Value) = UCase(Environ("Username")) Then
 
Upvote 0
You can use ucase to make both the cell value and Environ("Username") upper case so that the case does not matter as you are comparing all upper case to all upper case.
 
Upvote 0
Thanks guys for the quick responses. I'm not extremely familiar with how ucase works, so one other question about it. If I do use ucase, will the input not matter no matter how they input it? Does it just make all letters in the string upper case? So, in my example, if the user types in JSmith1 to log in, the code and the cell will both read JSMITH1?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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