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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

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