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!
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,567
Messages
5,596,906
Members
414,110
Latest member
docops

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
Top