Lauren Thomas
New Member
Hello
I am working on the attached file that contains this macro. The idea is to sort the columns which contain merged cells via the number in row 6 but it's not quite working.
Please could you help me?
Best wishes
Lauren
Sub ColumnSort()
'
' ColumnSort Macro
'
Application.ScreenUpdating = False
With Sheets("SHOP COMPARISON")
.Range("G:CX").UnMerge
For x = 0 To 32
xx = .Cells(5, 7 + x * 3)
.Cells(2, 7 + x * 3) = xx
.Cells(2, 8 + x * 3) = xx + 0.1
.Cells(2, 9 + x * 3) = xx + 0.2
Next x
With .Sort
.SortFields.Clear
.SortFields.Add Key:=Range("G2:CX2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("G2:CX106")
.Header = xlNo
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
.Range("G2:CX2").ClearContents
For x = 0 To 32
For y = 3 To 7
.Range(.Cells(y, 7 + x * 3), .Cells(y, 8 + x * 3)).Merge
Next y
Next x
With .Range("G5:CX7")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End With
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
I am working on the attached file that contains this macro. The idea is to sort the columns which contain merged cells via the number in row 6 but it's not quite working.
Please could you help me?
Best wishes
Lauren
Sub ColumnSort()
'
' ColumnSort Macro
'
Application.ScreenUpdating = False
With Sheets("SHOP COMPARISON")
.Range("G:CX").UnMerge
For x = 0 To 32
xx = .Cells(5, 7 + x * 3)
.Cells(2, 7 + x * 3) = xx
.Cells(2, 8 + x * 3) = xx + 0.1
.Cells(2, 9 + x * 3) = xx + 0.2
Next x
With .Sort
.SortFields.Clear
.SortFields.Add Key:=Range("G2:CX2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Range("G2:CX106")
.Header = xlNo
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
.Range("G2:CX2").ClearContents
For x = 0 To 32
For y = 3 To 7
.Range(.Cells(y, 7 + x * 3), .Cells(y, 8 + x * 3)).Merge
Next y
Next x
With .Range("G5:CX7")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End With
Application.ScreenUpdating = True
MsgBox "Done"
End Sub