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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,215,352
Messages
6,124,457
Members
449,161
Latest member
NHOJ

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