Convert Variable String to Lowercase in Excel VBA

Log In Form using Excel VBA

Image 1

This is great for when you need to compare string values, from perhaps user generated infomation.  For this example I have taken it from a user log in screen.  I always forget whether a username or password is case sensative, and more importantly, did I use capitilisation anywhere within the user or password details…?  A very easy way to solve this problem is when the user logs in capture their log in and password and convert it it to a lowercase string for comparison against the saved log in info for that user.  You may be thinking why do this, well in Excel strings “Password” would be read completely different to “password”.

In this example I use the variables called LogInUsername & LogInPassword to capture the information the user enters into the log in box and password box respectively. I then convert this to lowercase using the the StrConv function in Excel VBA.  The code below is missing alot of other information that is irrelevent for this example.


LogInUsername = LogIn.LogInUsername.Value 'Captures log in name
LogInPassword = LogIn.LogInPassword.Value 'Captures password

If StrConv(Cells(X, 1), vbLowerCase) = LogInUsername And StrConv(Cells(X, 2),vbLowerCase) = LogInPassword Then

Call NextStage
Unload Me
Exit Sub
End If

Unload Me
End Sub

Code Example

Image 2

The line of code in green is the part that converts the saved log in and password information for that user to lowercase.  So, StrConv(Cells(X, 1), vbLowerCase) = LogInUsername takes goes to the cell, in this instance X,1 and converts the username saved there to lowercase to then compare against the username the user has enterered to log in.  The same goes for the password section as well – StrConv(Cells(X, 2),vbLowerCase) = LogInPassword

This ensures that no matter where a user uses capitilsation I can ensure that it won’t cause problems with logging in.  So “Password” would read the same as “PASSWORD” and “PaSsWoRd”.  This line of code can be modified as well, simply replace the vbLowerCase with vbProperCase and it will capitilise the first letter of every word for you.

786 thoughts on “Convert Variable String to Lowercase in Excel VBA

  1. Assista Iptv Brasil

    Ponto IPTV a melhor programacao de canais IPTV do Brasil, filmes, series, futebol, lutas, shows, documentarios em alta definicao de imagem e som em SD, HD, FULL HD, 4K. compativel com todos aparelhos do mercado Brasileiro.

  2. Aplicativo Series Tv

    Ponto IPTV a melhor programacao de canais IPTV do Brasil, filmes, series, futebol, lutas, shows, documentarios em alta definicao de imagem e som em SD, HD, FULL HD, 4K. compativel com todos aparelhos do mercado Brasileiro.

  3. hentaisea

    Sweet blog! I found it while browsing on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I ave been trying for a while but I never seem to get there! Many thanks

  4. see

    There is perceptibly a lot to identify about this. I suppose you made some good points in features also.

  5. 출장서비스

    Very nice post i must say wedkarstwo.Very nice post i must say wedkarstwo.Very nice post i must say wedkarstwo.Very nice post i must say wedkarstwo.Very nice post i must say wedkarstwo.

  6. Royce Skocilich

    We are a group of volunteers and opening a new scheme in our community. Your website provided us with valuable info to work on. You’ve done an impressive job and our entire community will be thankful to you.

  7. 출장

    It as hard to come by knowledgeable people in this particular subject, but you sound like you know what you are talking about! Thanks

  8. Theo Dopico

    Simply wish to say your article is as astonishing. The clarity in your post is simply great, and I could assume you are an expert on this subject. Well with your permission let me grab your RSS feed to keep updated with forthcoming post. Thanks a million and please keep up the gratifying work.

  9. Kaylee

    Usually I do not read article on blogs, but I would like to say that this write-up very pressured me to take a look at and do so! Your writing taste has been surprised me. Thanks, quite great article.

  10. Lucila Ripke

    Wow, wonderful weblog structure! How long have you ever been blogging for? you make blogging look easy. The full look of your website is excellent, as well as the content!

Comments are closed.