Delete non visible rows after filter - not working

WaqasTariq

Board Regular
Joined
Jun 26, 2012
Messages
58
Office Version
  1. 365
Hi,
So I think I have what I need, but it is not working. I am trying to delete all filtered-out rows. (temp1 worksheet is hidden from view) example worksheet: Example.xlsm

VBA Code:
Option Explicit
Public l_DPI_LastRow1 As Long
Public s_WeekDayNames1() As String

Sub Button1_Click()
    WkS_Temp1.Range("A:C").Clear
    
    ReDim s_WeekDayNames1(1 To 7)
    s_WeekDayNames1(1) = "Mon"
    s_WeekDayNames1(2) = "Tue"
    ' So on...
    
    l_DPI_LastRow1 = WkS_Input.Cells(Rows.Count, "A").End(xlUp).Row
    
    WkS_Input.Range("A1:C" & l_DPI_LastRow1).Copy
        WkS_Temp1.Range("A1" & ":C" & l_DPI_LastRow1).PasteSpecial xlPasteValues
    
    ' Delete all rows where cell has a specific value
        WkS_Temp1.AutoFilterMode = False
        WkS_Temp1.Range("A1:C" & l_DPI_LastRow1).AutoFilter Field:=1, Criteria1:=s_WeekDayNames1(1)
        WkS_Temp1.Range("A1:A" & l_DPI_LastRow1).Offset(1).SpecialCells(12).EntireRow.Delete '.ClearContents
        WkS_Temp1.AutoFilterMode = False
    
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Are you trying to delete all rows where col A has Mon, or all rows that do not have Mon?
 
Upvote 0
Are you trying to delete all rows where col A has Mon, or all rows that do not have Mon?
I am sorry for not clarifying earlier. I am tried to delete all rows where col A does not have Mon. Thank you
 
Upvote 0
In that case try
VBA Code:
WkS_Temp1.Range("A1:C" & l_DPI_LastRow1).AutoFilter Field:=1, Criteria1:="<>" & s_WeekDayNames1(1)
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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