Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have data dump of year 2010,2011,2012,2013, out which my macro should search Column Header "Submit_Year" and under that column should filter data of year 2010,2011,2012 and delete them.

Sub Main()
Dim ws As Worksheet
Dim rng1 As Range
'Dim strin As String
Dim rng2  As Range
Set ws = Sheets("PivotData")
Application.ScreenUpdating = False
'Set rng1 = ws.Range("T2:T65000")
Set rng1 = Cells.Find("Submit_Year")

Dim strin() As Variant

For i = 0 To 2

strin = Array("2010", "2011", "2012")
For Each rng2 In rng1.Columns
Call FilterCull(rng2, strin(i))
Next
Application.ScreenUpdating = True

Next i
End Sub

Sub FilterCull(ByVal rng2, ByVal strin)
With rng2
 .Parent.AutoFilterMode = False
 .AutoFilter Field:=1, Criteria1:=strin
.EntireRow.Delete
 .Parent.AutoFilterMode = False
End With
End Sub

But after running this it deletes the column hearder row and not the data which contains year 2010,2011, 2012

Request for help.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.