Reverse Word/String in Excel using VBA

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
707
Office Version
  1. 365
  2. 2010
Im taking one of those free continuing education courses to maintain my designation...anyway, one of the tasks is to make a loop that reverse the string in Excel, but im totally lost...could someone help me, pleasE?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I have a custom function set up to do this, but you should be able to modify it into a macro if needed:
Code:
Function REVERSESTRING(c) As String
    Dim i As Integer
    For i = Len(c) To 1 Step -1
        my_string = my_string & Mid(c, i, 1)
    Next i
    REVERSESTRING = my_string
End Function

This would change "Adam Zapple" into "elppaZ madA"
 
Last edited:
Upvote 0
Nice code Juggler,

I was playing with this as it interested me, thought i would paste what i had anyway.

Code:
Sub SrtRev() 
    Dim x As Long, str As String, var() As Variant
     
    str = "ABCDEFG" 'define string
     
    For x = 1 To Len(str)
       ReDim Preserve var(x)
       var(x) = Mid(str, x, 1)
    Next


    For x = LBound(var) To UBound(var) / 2
        tmp = var(UBound(var) - x)
        var(UBound(var) - x) = var(x)
        var(x) = tmp
    Next x
    
    For x = LBound(var) To UBound(var) - 1
        MsgBox var(x)
    Next x
 
End Sub

Mostly the same method
 
Last edited:
Upvote 0
VBA has a function StrReverse

Try
Code:
Dim MyString As String, RevString As String

MyString = "Adam Zapple"
RevString = StrReverse(MyString)
MsgBox RevString

M.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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