Mega Quick VBA Amendement

MrMaker

Board Regular
Joined
Jun 7, 2018
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Afternoon all,

Really quick one.

I have some code (below) that generally works fine (to filter sheets), however, I don't want it to run on a new sheet called 'Summary' and I am getting a debug error.
Can someone add a line to basically say 'ignore Summary sheet' and run only on "Sheet 1". "Sheet 2" and "Sheet 3"

Thank you in advance


VBA Code:
Private Sub Workbook_Open()

Dim Sht As Worksheet, R As Range

Application.ScreenUpdating = False

For Each Sht In Me.Worksheets

    If Sht.Name <> "Data Selection" Then

        Set R = Sht.Range("A1").CurrentRegion

        R.AutoFilter field:=1, Criteria1:="<>" & Sheets("Data Selection").Range("A1")

        On Error Resume Next

        Set R = R.Offset(1, 0).SpecialCells(xlCellTypeVisible)

        On Error GoTo 0

        Sht.AutoFilterMode = False

        If Not R Is Nothing Then R.EntireRow.Delete

    End If

    Sht.Rows.RowHeight = 25

Next Sht

With Sheets("Data Selection")

    .Range("A1").Value = .Range("A1").Value

    .Rows.RowHeight = 25

    .Visible = xlHidden

End With

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
VBA Code:
If Sht.Name <> "Data Selection" And Sht.Name <> "Summary" Then
 
Upvote 0
Thank you for your quick reply.

I then get a debug error with the following line in yellow

R.AutoFilter field:=1, Criteria1:="<>" & Sheets("Data Selection").Range("A1")

(For context, the cell A1 in 'Data Selection' is the criteria used to select the autofilters

Any ideas?
 
Upvote 0
Do you have any data in & around A1 on the sheet when you get the error?
 
Upvote 0
It just has a name in it, which then filters the three data tabs.
The filtering happens fine, but then something goes wrong.
I'm a VBA amateur so any help is appreciated :)
 
Upvote 0
Add this message box as shown
Rich (BB code):
For Each Sht In Me.Worksheets

    If Sht.Name <> "Data Selection" Then

        Set R = Sht.Range("A1").CurrentRegion
        MsgBox Sht.Name & vbLf & R.Address
        R.AutoFilter field:=1, Criteria1:="<>" & Sheets("Data Selection").Range("A1")
What does it say just before you get the error
 
Upvote 0
It says:

Driver $A$1:$N$1448
Vehicle $A$1:$M$10
Collisions $A$1:$M$7
FAQs $A$1
 
Upvote 0
In that case the problem is with the sheet called FAQs, in that there is no data to filter
 
Upvote 0
That's right, its just a screenshot of some FAQ's

How can I fix this?

What do the Driver/Vehicle/Collisions references mean? As There is more data in Collisons and Vehicle than that suggests....


Thank you
 
Upvote 0
They are the range of the current region.
If you have more data in those sheets it suggest that you have totally blank rows & or columns.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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