VBA user defined function needs lower case string

Ricardo Caicedo

New Member
Joined
Aug 21, 2014
Messages
43
Hello again </SPAN>


I am having problems trying to convert a string variable inside a user defined function to lower case. The function pass two string variables (word & Name) and I assign them to a temp variable. The StrComp() function is not compiling, it give me a error …Any Help….</SPAN>




Function WordMatch(Word, Name)</SPAN>
Dim i As Integer</SPAN>
Dim NumWords As Integer</SPAN>
Dim StrTrim As String, StrAux As String, StrWLow As String, StrNLow As String</SPAN>

'Count the words inside the cell</SPAN>

StrTrim = WorksheetFunction.Trim(Word) 'Trim spaces from Word</SPAN>
StrAux = WorksheetFunction.Substitute(StrTrim, " ", "") 'Substitute spaces for nothing</SPAN>
NumWords = Len(StrTrim) - Len(StrAux) + 1 'Number spaces plus one is the number of words</SPAN>

StrWLow = StrConv(Word, VbStrConv.LowerCase)</SPAN></SPAN>
StrNLow = StrConv(Name, VbStrConv.LowerCase)
</SPAN></SPAN>


If NumWords = 1 Then</SPAN>
If StrComp(StrWLow, StrNLow, vbTextCompare) Then</SPAN>
WordMatch(Word, Name) = "True"</SPAN>
End If</SPAN>
End If</SPAN>


End Function</SPAN>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this...

Code:
StrWLow = StrConv(Word, [COLOR=#ff0000]vbLowerCase[/COLOR])
StrNLow = StrConv(Name, [COLOR=#ff0000]vbLowerCase[/COLOR])
 
Upvote 0
Try this...

Code:
StrWLow = StrConv(Word, [COLOR=#ff0000]vbLowerCase[/COLOR])
StrNLow = StrConv(Name, [COLOR=#ff0000]vbLowerCase[/COLOR])
Or even this...

Code:
StrWLow = LCase(Word)
StrNLow = LCase(Name)
 
Upvote 0
I am having problems trying to convert a string variable inside a user defined function to lower case. The function pass two string variables (word & Name) and I assign them to a temp variable. The StrComp() function is not compiling, it give me a error …Any Help….

Function WordMatch(Word, Name)
Dim i As Integer
Dim NumWords As Integer
Dim StrTrim As String, StrAux As String, StrWLow As String, StrNLow As String

'Count the words inside the cell

StrTrim = WorksheetFunction.Trim(Word) 'Trim spaces from Word
StrAux = WorksheetFunction.Substitute(StrTrim, " ", "") 'Substitute spaces for nothing
NumWords = Len(StrTrim) - Len(StrAux) + 1 'Number spaces plus one is the number of words

StrWLow = StrConv(Word, VbStrConv.LowerCase)
StrNLow = StrConv(Name, VbStrConv.LowerCase)


If NumWords = 1 Then
If StrComp(StrWLow, StrNLow, vbTextCompare) Then
WordMatch(Word, Name) = "True"
End If
End If

End Function

Is the purpose of all that code to see if the two arguments are identical ignoring letter casing? If so, I think this simpler function will work for you...
Code:
Function WordMatch(Word As String, Name As String) As Boolean
  WordMatch = LCase(Word) = LCase(Name)
End Function
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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