Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50057

A Macro to sort list after it has combined rows

$
0
0
I Have posted workbook that contains a macro which works fine but I also need it to sort them by ascending order everytime & to auto the macro to work everytime a value is added to either list.

I have attached Test workbook so you can see what I mean. Thx Jojo

Code:

Public Sub Combine()
Dim SH As Worksheet
Dim rng As Range
Dim srcRng As Range
Dim destRng As Range
Dim col As Range
Dim LastRow As Long
Dim iColour As Long 'NEW VARIABLE

Set SH = ActiveSheet
Set rng = SH.Range("A:B")

With SH
iColour = .Cells(1, "C").Interior.ColorIndex ''NEW CODE LINE
.Columns("C:C").ClearContents
For Each col In rng.Columns
LastRow = .Cells(Rows.Count, col.Column).End(xlUp).Row
Set srcRng = col.Cells(1).Resize(LastRow)
Set destRng = .Cells(Rows.Count, "C").End(xlUp)(2)
srcRng.Copy Destination:=destRng
Next col

On Error Resume Next
Range("C:C").SpecialCells(xlBlanks).Delete Shift:=xlUp
On Error GoTo 0

'NEW CODE LINE
Intersect(.Range("C:C"), .UsedRange).Interior.ColorIndex = iColour

End With

End Sub

Also I dont need the Interior color index part, but I copied it from elsewhere and dont know how to safely remove those lines.
Attached Files

Viewing all articles
Browse latest Browse all 50057

Trending Articles