HomeMicrosoft OfficeExcelReverse string in Excel VBA

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 article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021