Create a code that doesn't differentiate between capital and small letters

Fredrik1987

Board Regular
Joined
Nov 5, 2015
Messages
69
Hi!

I'm wondering if there's a way to create a simple VBA code that interprent a name, indifferently it starts with a capital letter or not. I've been searching around a little, and haven't really found anything.

For instance:
Column A consist of names (Hans, Gretel etc.). Where each name correspons to a value in column B (1, 2... etc.)
What I want the script to understand, is that if I insert "hans" instead of "Hans", the meaning are the same.
Also, is there a way to include misspelling (e.g. ahns instad of Hans)

Column AColumn B
Hans1
hans1
ahns1

<tbody>
</tbody>

This is just a simplified example of a large script, I think I read somewhere that it is possible to script in such a way that VBA only looks for the letters in a word, indepent of their arragement?
 
Last edited:
... the code you're refering to would be immensely useful for later use:)
Put all this in a standard module and run the 'CompareWords' macro
Code:
Sub CompareWords()
  Dim sWords As String, word1 As String, word2 As String, alpha1 As String, alpha2 As String
  Dim Bits1, Bits2
  Dim sMsg As String
  
  sWords = Application.InputBox("Enter two wors separated by a comma")
  sMsg = " : do not have the same letters"
  word1 = Split(LCase(sWords), ",")(0)
  word2 = Split(LCase(sWords), ",")(1)
  If Len(word1) = Len(word2) Then
    Bits1 = Split(StrConv(word1, vbUnicode), ChrW(0))
    Bits2 = Split(StrConv(word2, vbUnicode), ChrW(0))
    alpha1 = bubSort(Bits1)
    alpha2 = bubSort(Bits2)
    If alpha1 = alpha2 Then sMsg = " : have the same letters"
  End If
  MsgBox sWords & sMsg
End Sub


Function bubSort(ary) As String
  Dim tmp As String
  Dim i As Long, j As Long, lMin As Long, lMax As Long
  
  lMin = LBound(ary)
  lMax = UBound(ary)
  For i = lMin To lMax - 1
    For j = i + 1 To lMax
      If ary(i) > ary(j) Then
        tmp = ary(i)
        ary(i) = ary(j)
        ary(j) = tmp
      End If
    Next j
  Next i
  bubSort = Join(ary, "")
End Function
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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