vba to filter based off two criteria

ireland87

Board Regular
Joined
Jul 22, 2015
Messages
52
Hi

im trying to filter some data

all the data is contained within "master" and the filtered results need to be in "filter"

I want to have two criteria to filter with from within the "filter" sheet;
1. value of the cell ("C3")
2. dates values in cells ("C4") and ("C5")

Within the "master" sheet, column A contains dates and column B contains the possible values in "filter" C3

The below only has criteria 1 but doesn't work. Can anyone help?

' advanced filter
a = Worksheets("Master").Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To a
If Worksheets("Filter").Range("C3").Select Then
Worksheets("Master").Rows(i).Copy
Worksheets("Filter").Activate


b = Worksheets("Filter").Cells(Rows.Count, 1).End(xlUp).Row


Worksheets("Filter").Cells(b + 1).Select
ActiveSheet.Paste
End If
Next
Application.CutCopyMode = False
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
try something like this:
Code:
Sub test()
With Worksheets("Master")
 lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
 datarr = .Range(.Cells(1, 1), .Cells(lastrow, 2))
End With
With Worksheets("Filter")
 nextrow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
 matchdata = .Range(.Cells(3, 3), .Cells(3, 3))
 matchdate1 = .Range(.Cells(4, 3), .Cells(4, 3))
 matchdate2 = .Range(.Cells(5, 3), .Cells(5, 3))
  
 For i = 1 To lastrow
  If datarr(i, 2) = matchdata Then
   If datarr(i, 1) = matchdate1 Or datarr(i, 1) = matchdate2 Then
       
      .Cells(nextrow, 1) = datarr(i, 1)
      .Cells(nextrow, 2) = datarr(i, 2)
      nextrow = nextrow + 1
   End If
  End If
 Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

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