Alternatives to Boolean

Rocky.ca

New Member
Joined
Mar 20, 2011
Messages
3
How can I change the output from the following code to something instead of true or false? perhaps yes and no?

Function Palindrome(StrTest As String) As Boolean
Dim temp As String
Dim i As Long

For i = 1 To Len(StrTest)
If Mid(StrTest, i, 1) Like "[0-9A-Za-z]" Then
temp = temp & UCase(Mid(StrTest, i, 1))
End If
Next i

Palindrome = temp = StrReverse(temp)
End Function
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
One way:
Code:
Function Palindrome(StrTest As String) As String
    Palindrome = IIf(UCase(StrTest) = UCase(StrReverse(StrTest)), "Yes", "No")
End Function
 
Upvote 0
Try

Code:
Function Palindrome(StrTest As String) As String
Dim temp As String
Dim i As Long

For i = 1 To Len(StrTest)
If Mid(StrTest, i, 1) Like "[0-9A-Za-z]" Then
temp = temp & UCase(Mid(StrTest, i, 1))
End If
Next i

Palindrome = IIf(temp = StrReverse(temp), "Yep", "Nope")
End Function
[
 
Upvote 0
Or
Code:
Function Palindrome(ByVal sInp As String) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = "(\W)"
        .Global = True
        sInp = LCase(.Replace(sInp, ""))
    End With
    Palindrome = IIf(sInp = StrReverse(sInp), "Yes", "No")
End Function
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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