change code to stop sheet selecting or activating

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,126
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

I want to change my code to just run without activating or selecting the sheet.

Its not a major problem of course, but its just neater.

I have been trying to figure it out, but cannot, so please see code below that works.

It loops the 6 sheets and then goes back to the main sheet(meetings)

your time is appriciated. Dave

Code:
Sub REMOVE_NON_MATCHING_GRADES()
GRADE = Mid(Range("'MEETINGS'!$H$1"), 7, 1)
    For A = 1 To 6
        Sheets("TRAP " & A).Select
        LR = Range("K" & Rows.Count).End(xlUp).Row
            For i = LR To 4 Step -1
                If Not Range("k" & i).Value Like GRADE & "*" Then Rows(i).Delete
            Next i
    Next A
    Sheets("MEETINGS").Select
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You can do something like this:

Code:
Sub REMOVE_NON_MATCHING_GRADES()
GRADE = Mid(Range("'MEETINGS'!$H$1"), 7, 1)
    For A = 1 To 6
        With Sheets("TRAP " & A)
        LR = .Range("K" & .Rows.Count).End(xlUp).Row
            For i = LR To 4 Step -1
                If Not .Range("k" & i).Value Like GRADE & "*" Then .Rows(i).Delete
            Next i
         End With
    Next A
End Sub

Using an autofilter is probably a faster way to delete rows.
 
Upvote 0
Hi Rory

Worked perfectly, many thanks.

Autofilter is good, but the way i am using building this, this approach is easier for me.

thanks again

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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