Filter with conditional custom column?

Nothnless

Board Regular
Joined
Apr 28, 2016
Messages
142
Hi, is there syntax for filtering using an if statement in a custom added column? I don't have dax.

example: If paramater1 = "Yes" then filter column1 to paramater1 elseif paramater1 = "No" then filter column2 to paramater1

Thanks.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Public Sub Filter1()
Dim rng As Range
Dim iCol As Integer

Select Case parameter1
   Case "Yes"
        iCol = 1
    Case "No"
        iCol = 2
End Select

Range("A1").Select
Set rng = ActiveSheet.UsedRange
Selection.AutoFilter
rng.AutoFilter Field:=iCol, Criteria1:=parameter1
End Sub
 
Upvote 0
Code:
Public Sub Filter1()
Dim rng As Range
Dim iCol As Integer

Select Case parameter1
   Case "Yes"
        iCol = 1
    Case "No"
        iCol = 2
End Select

Range("A1").Select
Set rng = ActiveSheet.UsedRange
Selection.AutoFilter
rng.AutoFilter Field:=iCol, Criteria1:=parameter1
End Sub

This is a subroutine right? I can put this in, or call it from Power Query?
 
Upvote 0
if you have a query, you wont need the code.
My main query does a whole lot of other stuff but I want to primitively filter the query based on the conditions of a cell that the user selects from a drop down. I've already created the parameter queries that feeds into my main query to get the selections but I'm stuck on being able to filter my main query based on the cell selection. I hope this makes more sense, thanks.
 
Upvote 0
Never mind I figured it out. I first had to create a column [dummy] saying if paramater1 = "Yes" then [column1] elseif [column2]. Then I created another column [dummy2] saying if "drop down selection" equals [dummy] then true else false. Then I set the [dummy2] filter to true.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,750
Messages
6,174,290
Members
452,554
Latest member
Louis1225

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