Macro using Cell value in filter

jonashvid

Board Regular
Joined
Aug 27, 2005
Messages
52
Hey I have this Macro:

Sub indbyrdes()

Sheets("Premier League").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$E$1521").AutoFilter Field:=2, Criteria1:="Liverpool"
ActiveSheet.Range("$A$1:$E$1521").AutoFilter Field:=5, Criteria1:="Arsenal"
Range("A301:E1300").Select
Selection.Copy
Sheets("Database").Select
Range("C12").Select
ActiveSheet.Paste
Columns("C:C").EntireColumn.AutoFit
Range("C17").Select
End Sub

How can I replace Criteria1:"Liverpool" with a reference to a string in a specific cell. For example if I type "Blackburn" in a cell then this value is used instead of "Liverpool"..?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Depending on a number of assumptions, this can work nicely:

Code:
Sub indbyrdes()

    With Sheets("Premier League").UsedRange
        .AutoFilter 2, [Database!A1]
        .AutoFilter 5, [Database!A2]
        .Offset(1).SpecialCells(xlCellTypeVisible).Copy [Database!C12]
        Sheets("Database").Columns(3).AutoFit
        .AutoFilter
    End With

End Sub

Cells A1 and A2 on the sheet Database contain the team names to be used in the filter.

Wigi
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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