Changing order of the digits in a number in excel using VBA code

aaa125

New Member
Joined
Oct 9, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I want to change the order of a string such as 32cd4f18 so that it gives an output of 23dcf481. So the string should be swapped in pairs. If someone could help me with a VBA code that would be very helpful.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You did not say if you have just the one text string to process (as your post seems to indicate) or a column's worth of data to process. Here is a UDF (user defined function) that can be used for one or a somewhat small number of text strings (if you have a large list to process, a macro would probably be more efficient)...
VBA Code:
Function ReversePairs(S As String) As String
  Dim X As Long
  For X = 1 To Len(S) Step 2
    ReversePairs = ReversePairs & StrReverse(Mid(S, X, 2))
  Next
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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