Supposedly this is the data of a Single Cell A1:
Score Remarks
1-10 25 25-38 jk 100-150 merryI need a shortcut where I can Allign in such a way that the spacing between the data is uniform.
Score Remarks
1-10 25
25-38 jk
100-150 merry I need it like this. NOTE: Do not suggest to use SpaceBars in between, What if the data is huge?
32 Answers
Try the following user defined function:
Public Function PrettyOutput(sIN As String) As String Dim hr As String, i As Long, maxL As Long Dim U As Long hr = Chr(10) If InStr(1, sIN, hr) = 0 Then PrettyOutput = sIN Exit Function End If ary = Split(sIN, hr) U = UBound(ary) For i = 0 To U ary(i) = Application.WorksheetFunction.Trim(ary(i)) Next i maxL = 0 For i = 0 To U bry = Split(ary(i), " ") If Len(bry(0)) > maxL Then maxL = Len(bry(0)) Next i For i = 0 To U bry = Split(ary(i), " ") PrettyOutput = PrettyOutput & bry(0) & Application.WorksheetFunction.Rept(" ", maxL - Len(bry(0))) & " " & bry(1) & hr Next i PrettyOutput = Mid(PrettyOutput, 1, Len(PrettyOutput) - 1)
End FunctionUser Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I ALT-M opens a fresh module
- paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=myfunction(A1)
To learn more about macros in general, see:
and
and for specifics on UDFs, see:
Macros must be enabled for this to work!
So with data in A1, in B1 enter:
=PrettyOutput(A1)and format B1 with a font like Courier:
2Data -> Text to columns is what it sounds like you want. Don't try to keep everything in one cell, split it up among several cells.