Reverse Word/String in Excel using VBA

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
782
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,224,827
Messages
6,181,199
Members
453,022
Latest member
RobertV1609

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