PDA

View Full Version : VBA Help to Reverse a String without StrReverse function



malleshg24
08-16-2018, 12:43 PM
Hi Team,


Need your help to reverse the string in Column A and paste in Column B.
Through loop and without using STRREVERSE function. Sample Data as shown below









Column A




Column B






string




Result






sdfasf




fsafds






uios




soiu






kdsljf23




32fjlsdk




:think:

Thanks in advance

Regards,
Mallesh

YasserKhalil
08-16-2018, 01:50 PM
Try this UDF

Function strReverse(ByVal cell As Range) As String strReverse = VBA.strReverse(cell.Value)
End Function

pike
08-16-2018, 02:52 PM
Hello malleshg2,
Excel 2016 array formula
=IF(A1="","",CONCAT(MID(A1,1 + LEN(A1)-ROW(INDIRECT("1:" & LEN(A1))),1)))

malleshg24
08-16-2018, 06:53 PM
Hi Khalil and Pike

Thanks a lot both of you,
one of my friend challenged me to reverse the string, without using STRReverse function in VBA.
Is it possible i am new in coding. Thanks

Regards
Mallesh

YasserKhalil
08-16-2018, 09:15 PM
Hello ..
No problem. There must be always another way
Try this


Sub Test_ReverseString_UDF()
MsgBox ReverseString("Hello World")
End Sub


Function ReverseString(s As String)
Dim t As String
Dim n As Long

For n = Len(s) To 1 Step -1
t = t & Mid(s, n, 1)
Next n

ReverseString = t
End Function

malleshg24
08-16-2018, 09:40 PM
Superb !

Thank you so much Khalil and Poke for lovely solution.

Regards,
Mallesh

YasserKhalil
08-16-2018, 09:41 PM
You're welcome. Glad we can offer some help