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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,216,036
Messages
6,128,432
Members
449,452
Latest member
Chris87

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