VBA to Extract List Based on Criteria in 2 Columns

manona

New Member
Joined
Mar 22, 2016
Messages
40
Hi,
I'm looking for a macro that will - based on a selection - list all items that satisfy 2 criteria.
Basically there are 2 pick lists (one for fiscal year; one for province), which the user will select, and based on that, I would like all the codes for the chosen year and province to be listed.
Is that possible? Any help is really appreciated!!:)
Manon

TAB 1
Is the source with all the information:

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]FY[/TD]
[TD]PROV[/TD]
[TD]CODE[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]15-16[/TD]
[TD]ON[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]15-16[/TD]
[TD]ON[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]15-16[/TD]
[TD]AB[/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]15-16[/TD]
[TD]AB[/TD]
[TD]6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]15-16[/TD]
[TD]SK[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]15-16[/TD]
[TD]BC[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]16-17[/TD]
[TD]ON[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]16-17[/TD]
[TD]ON[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]16-17[/TD]
[TD]ON[/TD]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]16-17[/TD]
[TD]AB[/TD]
[TD]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]16-17[/TD]
[TD]AB[/TD]
[TD]6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]16-17[/TD]
[TD]SK[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]16-17[/TD]
[TD]BC[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]17-18[/TD]
[TD]ON[/TD]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]17-18[/TD]
[TD]SK[/TD]
[TD]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]17-18[/TD]
[TD]BC[/TD]
[TD]7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Notes*
- e.g. there are 2 values in ON in the first year, 3 in the second year, and 1 in the last year.


TAB 2

This is the results tab:

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Pick FY:[/TD]
[TD](pick list)[/TD]
[TD]Pick Prov.[/TD]
[TD](pick list)[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Province[/TD]
[TD]Code[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]List here[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I'm looking for the macro to list, starting in C4, and based on the items picked in C1 and E1, the codes for the chosen year and province.

So let's say we stick with ON:

If the user selects "15-16", we would have 2 results
C5 = 1, C6 = 2

If the user selects "16-17", we would have 3 results
C5 = 1, C6 = 2, C7 = 3

If the user selects "17-18", we would have 1 results
C5 = 3


A very big thank you in advance!!

Manon
 
How about
Code:
Sub manona()
   With Sheets("Sheet1")
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:C1").AutoFilter 1, Sheets("Sheet2").Range("C1").Value
      .Range("A1:C1").AutoFilter 2, Sheets("Sheet2").Range("E1").Value
      .AutoFilter.Range.Offset(1).Columns(3).Copy Sheets("Sheet2").Range("C4")
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0

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