Auto Filter but exclude lines or data that includes a certain word

oblix

Board Regular
Joined
Mar 29, 2017
Messages
183
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi there all
I have table that I allow users to click on icon to run vba to filter non blank rows before printing:

Rich (BB code):
Sub Prep_Received()
    With ThisWorkbook.Worksheets("Received")
        Range("$B$2:$F$3000").AutoFilter Field:=1, Criteria1:="<>"
    End With
End Sub

I woud like to exclude lines 3 to 547 as I have hiddden it from user. Alternatively to exclude lines which has contains word :"Opening Stock".

The same goes for unfiltering. With unfilter it should not unfilter lines 3 to 547 and should remain hidden. the current code is:

Rich (BB code):
Sub Clear_Prep_Received()
    With ThisWorkbook.Worksheets("Received")
        If .AutoFilterMode Then .AutoFilter.ShowAllData
    End With
End Sub

Any help would be appreciated and I will learn from your suggestions
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try extending the filter criterias as follow:
VBA Code:
    ActiveSheet.Range("$B$2:$F$3000").AutoFilter Field:=1, Criteria1:="<>", _
        Operator:=xlAnd, Criteria2:="<>*Opening stock*"

For clearing the filter, indeed apply a filter with the following criteria:
VBA Code:
    ActiveSheet.Range("$B$2:$F$3000").AutoFilter Field:=1, Criteria1:="<>*Opening stock*"

Try...
 
Upvote 0
I woud like to exclude lines 3 to 547 as I have hiddden it from user
If you have used Rows > Hide to hide the rows, unfiltering or even removing the AutoFilter won't make them visible.
Only Rows > Unhide or changing the Row Height will make them visible.
 
Upvote 0
Thank you for quick reply
It worked ...... sort of
I changed my code to:
Filter:
Rich (BB code):
Sub Prep_Received()
    With ThisWorkbook.Worksheets("Received")
        Range("$B$2:$F$4905").AutoFilter Field:=4, Criteria1:="<>", _
        Operator:=xlAnd, Criteria2:="<>*OPENING STOCK*"
      End With
End Sub

and unfilter/clear filter to:
Rich (BB code):
Sub Clear_Prep_Received()
       ActiveSheet.Range("$B$2:$F$4905").AutoFilter Field:=4, Criteria1:="<>*OPENING STOCK*"
End Sub


The clear filter / unfilter works fine but when I filter it starts at line963 where it was supposed to start at line 548.....
so it hides more than it should.
 
Upvote 0
Okay Solved the problem.... but
Now when I send information from another sheet...... it overides the first line info (line3) instead of starting in line 485 (only does this when line 3 to 485 is hidden/filtered out
the code to send from sheet "PO" to sheet"Received" is:

Rich (BB code):
Sub Send_to_Received()
Call TurnStuffOff
    Call Clear_PO_Filter
    Call Adv_Filter_PO
   
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long

'Set variables for copy and destination sheets
Set wsCopy = Worksheets("PO")
Set wsDest = Worksheets("Received")

'2. Find first blank row in the destination range based on data in column B
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, 1).End(xlUp).Offset(1).Row

'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "AS").End(xlUp).Row

'3. Copy & Paste Data
wsCopy.UsedRange.Copy
wsCopy.Range("AS6:AY" & lCopyLastRow).Copy

'wsDest.Range ("B" & lDestLastRow)
wsDest.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

'Select the destination sheet
wsDest.Activate
Range("A1").Select
Call TurnStuffOn
End Sub
 
Upvote 0
If you think this is due to filtered rows, then remove all filters at the beginning and apply them just before the end of the macro

Remember that paste always works on contiguous cells, hidden or visible doesn't matter.
 
Upvote 0
Solution
Cleared contents in blanks cells...working now
thanks for inputs
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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