If and Max function together - VBA

drsudhakar

New Member
Joined
Jan 25, 2018
Messages
6
Dear all
I need to get average, max and min of cells (all numbers) in column P, if data in column R is = 1 or >1.

My dataset has varying number of rows depending on amount of work happened, for which I am using dynamic last row (LR). I could figure out the formula for average as below :

sheet.Range("P" & LR + 2).Formula = "=AVERAGEif(r2:r" & LR & ", "">1"", P2:P" & LR & ")"


But, for max or min function, the same is pending. Code I came for Max is as follows :

sheet.Range("P" & LR + 3).FormulaArray = "=MAX(if(r2:r" & LR & ", "">1"", P2:P" & LR & "), )"



Can somebody help please.

Thanks in advance for sharing your knowledge. I am a biologist and new to VBA.

regards
drsudhakar
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try it like this:

Rich (BB code):
sheet.Range("P" & LR + 3).FormulaArray = "=MAX(IF(R2:R" & LR & ">1", P2:P" & LR & "))"


WBD
 
Upvote 0
Try it like this:

Rich (BB code):
sheet.Range("P" & LR + 3).FormulaArray = "=MAX(IF(R2:R" & LR & ">1", P2:P" & LR & "))"


WBD


Hi wideboydixon
Thanks for suggestion. But, the array provided shows compile error in Excel 2013. Could you please identify the issue.


regards
drsudhakar
 
Upvote 0
Hi all
I thought, replacing Max with MIN in the above formula will provide minimum value. But, that doesn't work. Can somebody help please.


sheet.Range("Q" & LR + 4).Formula = "=MIN(IF(R2:R" & LR & ">1, P2:P" & LR & "))"

Advance thanks for response.

regards
drsudhakar
 
Upvote 0

Forum statistics

Threads
1,225,768
Messages
6,186,924
Members
453,387
Latest member
uzairkhan

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