character spacing

thenos09

New Member
Joined
Aug 4, 2011
Messages
7
I would just like to know how to format a cell to make a space every 2 characters

ie. cell A1 = 1234567890

I want to the cell to display 12 34 56 78 90

the data in cell A1 will vary but I always want a space after every 2nd character
 
I did that.

So in A1 i have 'Hello'

Then in A2 i have '48656C6C6F'

Then in A3 i have '=InsertSpace(A2)' and in the cell it says '#VALUE!'
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Why not do it all at once? I assume that your asc2hex function is something like below but without the blue bits. If you add the blue bits, doesn't that give you the result you want? If you want what you currently have in A2 as well, then just rename the function below as, say, asc2hexspace and use in A3:
=asc2hexspace(A1)

Rich (BB code):
Function asc2hex(str As String) As String
    Dim I As Long
    
    For I = 1 To Len(str)
        asc2hex = asc2hex & Hex(Asc(Mid(str, I, 1))) & " "
    Next I
    asc2hex = RTrim(asc2hex)
End Function
 
Upvote 0
Here is a UDF you can use to do all the work (convert the text to hex values separated by spaces)...
Code:
Function Asc2Hex(S As String) As String
  Dim X As Long, B() As Byte, H() As String
  B = S
  ReDim H(LBound(B) To UBound(B))
  For X = LBound(B) To UBound(B)
    If X Mod 2 Then
      H(X) = " "
    Else
      H(X) = Hex(B(X))
    End If
  Next
  Asc2Hex = Trim(Join(H, ""))
End Function
So, if you text string "Hello my name is Brett" is in A1, then this formula...

=Asc2Hex(A1)

will output this...

48 65 6C 6C 6F 20 6D 79 20 6E 61 6D 65 20 69 73 20 42 72 65 74 74
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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