Reverse string in Excel VBA

In this post, you will learn how to reverse a string in your excel spreadsheet using Excel VBA with an example.

Reverse string in Excel VBA

To reverse a string, follow these steps.

  • First, insert a command button.
  • Enter the following code.

Code:

Private Sub CommandButton1_Click()
Dim String1 As String
Dim StringReverse As String
Dim Char As String
Dim Size As Integer
Dim Point As Integer
String1 = InputBox("String1: ")
Size = Len(String1)
StringReverse = ""
For Point = Size To 1 Step -1
Char = Mid(String1, Point, 1)
StringReverse = StringReverse & Char
Next Point
MsgBox "String reversed: " & StringReverse
End Sub

Click on the run button or click the command button. An input dialog box opens, enter the text and click okay.

A message box with the reversed string appears.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...