Using two Change Macros in one worksheet

mgraham

New Member
Joined
Apr 18, 2013
Messages
2
I have a worksheet "OPEN", and would like to apply both:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim i As Long
Set rng = Target.Parent.Range("B:B")
If Target.Count > 1 Then Exit Sub
If Intersect(Target, rng) Is Nothing Then Exit Sub
If LCase(Target.Value) = "closed" Then
i = Target.Row
Target.EntireRow.Cut Sheets("CLOSED").Cells(Rows.Count, "A").End(xlUp).Offset(1)
Cells(i, "B").EntireRow.Delete
End If
End Sub

and

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then
Range("A2:L100").Sort _
Key1:=Range("B1"), Order1:=xlAscending, _
Key2:=Range("A1"), Order2:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End If
End Sub

The first removes the rows if the validated column 'B' is equal to "closed", to a second worksheet "CLOSED". The second orders the rows by the same column, followed by column 'A'. Being brand new to macros, I've no clue how to make this happen... or if it's even possible...any help would be greatly appreciated!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Can't you just add the sort code below the code in the first sub?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim i As Long
    Set rng = Target.Parent.Range("B:B")
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, rng) Is Nothing Then Exit Sub
    If LCase(Target.Value) = "closed" Then
        i = Target.Row
        Target.EntireRow.Cut Sheets("CLOSED").Cells(Rows.Count, "A").End(xlUp).Offset(1)
        Cells(i, "B").EntireRow.Delete
    End If

    Range("A2:L100").Sort _
            Key1:=Range("B1"), Order1:=xlAscending, _
            Key2:=Range("A1"), Order2:=xlAscending, _
            Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
            Orientation:=xlTopToBottom

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,530
Messages
6,120,071
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top