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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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