• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to delete visible cells from range without deleting headers

ThrottleWorks

Excel Ninja
Hi,

I am trying to delete visible cells from a filtered range.
As of now I am able to do it however I am not sure where it is the correct way.

Is there a single line code, which will help me to delete visible cells from the range but will not delete headers.

At present I am using "Range(TempSht1.Cells(2, 1), TempSht1.Cells(TempLr, TempCol)).SpecialCells(xlCellTypeVisible).EntireRow.Delete" this line to avoid deleting header.

Can anyone please help me in this.

Code:
Set TempRng = TempSht1.Range(TempSht1.Cells(1, 1), TempSht1.Cells(TempLr, TempCol))
    On Error Resume Next
        Selection.AutoFilter
            TempRng.AutoFilter Field:=Col, Criteria1:="=Honda", Operator:=xlAnd
            TempLr1 = TempSht1.Cells(Rows.Count, Col).End(xlUp).Row
           
            If TempLr1 > 1 Then
                Range(TempSht1.Cells(2, 1), TempSht1.Cells(TempLr, TempCol)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            End If
       
        Selection.AutoFilter
    On Error GoTo 0

Set TempRng = TempSht1.Range(TempSht1.Cells(1, 1), TempSht1.Cells(TempLr, TempCol))
On Error Resume Next
Selection.AutoFilter
TempRng.AutoFilter Field:=Col, Criteria1:="=Honda", Operator:=xlAnd
TempLr1 = TempSht1.Cells(Rows.Count, Col).End(xlUp).Row
If TempLr1 > 1 Then
Range(TempSht1.Cells(2, 1), TempSht1.Cells(TempLr, TempCol)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
Selection.AutoFilter
On Error GoTo 0
 

Hi !

No need to select neither SpecialCells
as Copy like Delete methods use only visible cells !
From source range with headers row, just need an Offset.

With a dummy sample workbook, I could post a demonstration …
 
Back
Top