Text alignment in a cell
-
ajoy123rocks -
September 16, 2021 at 9:05 AM -
Thread is marked as Resolved.
-
-
-
I have a column containing the values as below
asdafdafa,v.
asdadad,a.
sawqdqaf,b.
asdas,x.
wretweftettt,s.
i need to align the above text in the below format
Can you please help?
All the initials v., a., b., x., s. Must align in a straight line in their respective rows
-
Presuming that your names are in column A from row 1 and have a single comma and a 2 charcter initial you could use this macro. To keep the initials aligned you will have to format the column with a monospaced font (ex. Courier New).
Code
Display MoreOption Explicit Sub Pad_With_Space() Dim x, lr, rng As Range, pos, maxLen 'detect max lenght of names lr = Range("A" & Rows.Count).End(xlUp).Row For x = 1 To lr Set rng = Range("A" & x) If Len(rng) > maxLen Then maxLen = Len(rng) Next x 'pad with spaces For x = 1 To lr Set rng = Range("A" & x) pos = InStr(1, rng, ",") rng = Left(rng, pos) & Space(maxLen - Len(rng) + 1) & Right(rng, 2) Next x End Sub
-
Thank you @rollis13.... the code worked to point
-
Glad having been of some help.
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!