Solved

Filter for year and delete entire row

Posted on 2015-02-17
2
78 Views
Last Modified: 2015-02-17
Hi,

I need some VB code to filter for year "2015" in Column C and delete entire rows

Many thanks
Seamus
0
Comment
Question by:Seamus2626
2 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 200 total points
ID: 40613788
Sub DeleteRows
   for introw = 99999 to 1 step -1
      if cells(introw,3)="2015" then
         rows(introw).delete
      end if
   next
End Sub
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 300 total points
ID: 40613789
HI,

pls try

    Range("C1").AutoFilter Field:=1, Criteria1:="2015"
    Range(Range("C2"), Range("C" & Cells.Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    ActiveSheet.Range("C1").AutoFilter

Open in new window

EDIT if you want to filter a date then use

    Range("C1").AutoFilter Field:=1, Criteria1:=">=" & CLng(DateValue("1.1.2015")), _
        Operator:=xlAnd, Criteria2:="<" & CLng(DateValue("1.1.2016"))
    Range(Range("C2"), Range("C" & Cells.Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    ActiveSheet.Range("C1").AutoFilter

Open in new window

Regards
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now