Hi,
I am struggling with VBA syntax to implement a Max If over multiple conditions on dynamic ranges.
I have a list of products and I want to find the most expensive according to 2 or more criterias.
On top of it the list of products is dynamic.
What would the correct syntax be for having a macro that returns 46 if the user inputs as chosen criterias: Blue Shirt?
I managed to get some results with a dynamic range using formulas of this sort
Selection.FormulaArray = _
"=MAX(IF(Sheet1!R6C6:R96C6=""Blue"",IF(Sheet1!R6C5:R96C5=""Skirt"",Sheet1!R6C7:R96C7)))"
but I don't know how to convert the formula above into a dynamic formula with "Cells()" and "for loops".
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]PRODUCTS[/TD]
[TD]COLOUR[/TD]
[TD]PRICE[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]BLUE[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]PANTS[/TD]
[TD]BLUE[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]PANTS[/TD]
[TD]YELLOW[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]YELLOW[/TD]
[TD]47[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]YELLOW[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]BLUE[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]BLUE[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]RED[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]PANTS[/TD]
[TD]YELLOW[/TD]
[TD]40[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]RED[/TD]
[TD]35[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]YELLOW[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]RED[/TD]
[TD]67[/TD]
[/TR]
</tbody>[/TABLE]
I am struggling with VBA syntax to implement a Max If over multiple conditions on dynamic ranges.
I have a list of products and I want to find the most expensive according to 2 or more criterias.
On top of it the list of products is dynamic.
What would the correct syntax be for having a macro that returns 46 if the user inputs as chosen criterias: Blue Shirt?
I managed to get some results with a dynamic range using formulas of this sort
Selection.FormulaArray = _
"=MAX(IF(Sheet1!R6C6:R96C6=""Blue"",IF(Sheet1!R6C5:R96C5=""Skirt"",Sheet1!R6C7:R96C7)))"
but I don't know how to convert the formula above into a dynamic formula with "Cells()" and "for loops".
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]PRODUCTS[/TD]
[TD]COLOUR[/TD]
[TD]PRICE[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]BLUE[/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD]PANTS[/TD]
[TD]BLUE[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]PANTS[/TD]
[TD]YELLOW[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]YELLOW[/TD]
[TD]47[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]YELLOW[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]BLUE[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]BLUE[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]RED[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]PANTS[/TD]
[TD]YELLOW[/TD]
[TD]40[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]RED[/TD]
[TD]35[/TD]
[/TR]
[TR]
[TD]SHIRT[/TD]
[TD]YELLOW[/TD]
[TD]46[/TD]
[/TR]
[TR]
[TD]SKIRT[/TD]
[TD]RED[/TD]
[TD]67[/TD]
[/TR]
</tbody>[/TABLE]