#1
|
|||
|
|||
Right-Aligning Data to a Column
Hi,
I have several rows of numbers with each row containing between 1 and 20 columns of numbers. I'd like to "right-align" the rows of numbers so that the last number in each row are aligned with each other. In other words, alignment is right-to-left, not-to-right. Example: C1 C2 C3 C4 C5 C6 C7 R1 5 6 7 5 4 3 R2 3 2 3 1 4 R3 8 9 R4 2 1 2 6 I'd like 3, 4 9, 6 to align under C7 and their predecessors to align in the cells preceding behind them. thank you, sunnyside |
#2
|
|||
|
|||
This macro will determine:
1) How many rows of data there are 2) How many columns of data there are 3) Cut the row of data and paste on same row so last column lines up There can be no blank cells in the middle of data on a single row. Code:
Sub AlignRight() Dim LC As Long, LR As Long, Rw As Long, Cnt As Long LR = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row LC = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1 For Rw = 1 To LR Cnt = Rows(Rw).SpecialCells(xlConstants).Cells.Count Rows(Rw).SpecialCells(xlConstants).Cut Cells(Rw, LC - Cnt) Next Rw End Sub |
#3
|
|||
|
|||
RE: aligning columns
Thank you!
This worked great. Sunnyside |
#4
|
|||
|
|||
how to give range
i need to selected range i select range from mouse it need little change above script |
Tags |
right align data cells |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can I change the horizontal scrollbar to scroll smoothly rather than column by column | carpat | Excel | 0 | 01-10-2012 09:34 AM |
Need to search a column for a macth and return a result from a third column | pdfaust | Excel | 2 | 02-03-2011 03:02 PM |
Aligning column text in a table | dpeattie | Word | 6 | 12-29-2010 04:59 PM |
2-Column Text Slides and Aligning Bullets | KitKatJM | PowerPoint | 1 | 03-09-2010 06:45 PM |
Inverting Data in a Column | mrdave100 | Word | 0 | 03-08-2010 01:27 PM |