1

I want to remove the filtered data using VBA code where the sheet has header(which should not be deleted) and the end is unknown.

I tried as below

ActiveSheet.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete

but it also removing the header. Please help. Thank you.

5
  • Have a look e.g. here: stackoverflow.com/questions/26930011/…
    – gembird
    Nov 18, 2014 at 12:13
  • but it is different scenario. I asked to remove the filtered data after header.
    – Anil
    Nov 18, 2014 at 12:17
  • That did what you want when I ran it. Is something else happening in your code that isn't shown here?
    – peege
    Nov 18, 2014 at 13:12
  • Make sure your Range doesn't include the header row? Nov 18, 2014 at 15:29
  • Check the range address first MsgBox ActiveSheet.UsedRange.Address. If it returns the correct address, there is no reason for your code not to work.
    – L42
    Nov 19, 2014 at 3:41

1 Answer 1

0

There is a DBExtract sheet which has header and filtered values. To remove the filtered values data. Please check with below example. That will keep your header and will remove the filtered records only.

Note while you select your range

Select your range as Maximum when you are not aware of the range. That's why I kept it as BF99999 ( BF is the last column that contains data and 99999.. you can chose max value.

  Sub DeleteFilteredData()

             Dim DbExtract As Worksheet
             Set DbExtract = ThisWorkbook.Sheets("Export Worksheet")
             DbExtract.Range("A2:BF9999").SpecialCell(xlCellTypeVisible).EntireRow.Delete

    End Sub
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.