madelca100
MIS
I've seen several sample of code that aligns columns, but they all use 'unbroken' lists.
Currently this is done manually.
By cutting and pasteing L/M to a matched I value.
Insert a row where there is an L value and no I value. etc.
Very error prone.
Note: I can't copy this data, sort it, and paste it back in because I also matches values in columns C & F. All the alignment must take place on this worksheet.
My data is as follows:
The data starts in row 11 column I
There is other data in the spreadsheet.
I need to be able to align the values in I and L.
Note that there are gaps in column I.
Column L is sorted ascending with no gaps.
I need to be able to insert rows to match the values in col I and col L
(col L and the number in M need to move together)
and move down the values of L and M when they don't match I/J (the numbers in J and M may be different for the same value in I/L.
I hope somebody out there has solved this already.
mike
This is a small sample of the before date:
col I J L M
-------------------------
53 1 251 1
62 1 253 4
82 1 256 5
192 1 257 2
258 2
247 2 280 2
282 1
252 2 464 1
253 1 521 1
254 2 544 4
256 2 611 1
635 1
258 2 636 1
263 1 795 1
280 7
after:
col I J L M
-------------------
53 1
62 1
82 1
192 1
247 2
251 1
252 2
253 1 253 4
254 2
256 2 256 5
257 2
258 2 258 2
263 1
280 7 280 2
282 1
464 1
521 1
etc. etc.
Sample of code that doesn't work for this situation:
Sub AlignLists()
'
' Code by Cy Bones @ Neowin.net
'
Worksheets("sumrdata").Activate
Columns("a:a").Copy Destination:=Worksheets("Sheet2").Range("a1")
Range("a", Range("a").End(xlDown)).Copy _
Destination:=Worksheets("Sheet2").Range("A1").End(xlDown).Offset(1, 0)
Sheets("Sheet2").Activate
Range("A1", Range("A1").End(xlDown)).Sort Key1:=Range("A2"), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("B1"), Unique:=True
Columns("A:A").Delete Shift:=xlToLeft
Worksheets("Sheet1").Range("A11").Copy _
Destination:=Worksheets("Sheet2").Range("B1")
Range("B2", Range("A2").End(xlDown).Offset(0, 2)).FormulaR1C1 = _
"=VLOOKUP(RC1,Sheet1!C1:C2,COLUMN()-1,FALSE)"
Range("D2", Range("C2").End(xlDown).Offset(0, 2)).FormulaR1C1 = _
"=VLOOKUP(RC1,Sheet1!C3:C4,COLUMN()-3,FALSE)"
With Range("A1").CurrentRegion
.Value = .Value
End With
Range("A1").CurrentRegion.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Columns("A:A").Delete Shift:=xlToLeft
Columns("A:E").EntireColumn.AutoFit
End Sub
Currently this is done manually.
By cutting and pasteing L/M to a matched I value.
Insert a row where there is an L value and no I value. etc.
Very error prone.
Note: I can't copy this data, sort it, and paste it back in because I also matches values in columns C & F. All the alignment must take place on this worksheet.
My data is as follows:
The data starts in row 11 column I
There is other data in the spreadsheet.
I need to be able to align the values in I and L.
Note that there are gaps in column I.
Column L is sorted ascending with no gaps.
I need to be able to insert rows to match the values in col I and col L
(col L and the number in M need to move together)
and move down the values of L and M when they don't match I/J (the numbers in J and M may be different for the same value in I/L.
I hope somebody out there has solved this already.
mike
This is a small sample of the before date:
col I J L M
-------------------------
53 1 251 1
62 1 253 4
82 1 256 5
192 1 257 2
258 2
247 2 280 2
282 1
252 2 464 1
253 1 521 1
254 2 544 4
256 2 611 1
635 1
258 2 636 1
263 1 795 1
280 7
after:
col I J L M
-------------------
53 1
62 1
82 1
192 1
247 2
251 1
252 2
253 1 253 4
254 2
256 2 256 5
257 2
258 2 258 2
263 1
280 7 280 2
282 1
464 1
521 1
etc. etc.
Sample of code that doesn't work for this situation:
Sub AlignLists()
'
' Code by Cy Bones @ Neowin.net
'
Worksheets("sumrdata").Activate
Columns("a:a").Copy Destination:=Worksheets("Sheet2").Range("a1")
Range("a", Range("a").End(xlDown)).Copy _
Destination:=Worksheets("Sheet2").Range("A1").End(xlDown).Offset(1, 0)
Sheets("Sheet2").Activate
Range("A1", Range("A1").End(xlDown)).Sort Key1:=Range("A2"), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("B1"), Unique:=True
Columns("A:A").Delete Shift:=xlToLeft
Worksheets("Sheet1").Range("A11").Copy _
Destination:=Worksheets("Sheet2").Range("B1")
Range("B2", Range("A2").End(xlDown).Offset(0, 2)).FormulaR1C1 = _
"=VLOOKUP(RC1,Sheet1!C1:C2,COLUMN()-1,FALSE)"
Range("D2", Range("C2").End(xlDown).Offset(0, 2)).FormulaR1C1 = _
"=VLOOKUP(RC1,Sheet1!C3:C4,COLUMN()-3,FALSE)"
With Range("A1").CurrentRegion
.Value = .Value
End With
Range("A1").CurrentRegion.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Columns("A:A").Delete Shift:=xlToLeft
Columns("A:E").EntireColumn.AutoFit
End Sub