Moonbeam111
Board Regular
- Joined
- Sep 24, 2018
- Messages
- 73
- Office Version
- 365
- 2010
How can I convert this to VBA Code?
Here is what I have:
Etc..
Is there a more streamlined code for this? I'm mostly having trouble with applying the IFERROR part across the VBA Code and the MIN function.
Excel Formula:
=IFERROR( MIN(1,IF('Sheet1'!F16="Missed Budget",0,IF(AND('Sheet2'!C23="",'Sheet2'!C22="Unknown"),"Percentage of Budget",IF(AND('Sheet1'!F16="Hit Budget",'Sheet2'!C20=1,E26="Success"),RANDBETWEEN('Sheet2'!D40,'Sheet2'!D41)*0.01/2,IF(AND('Sheet1'!F16="Hit Budget",'Sheet2'!C20=1,H26="Success"),RANDBETWEEN('Sheet2'!D40,'Sheet2'!D41)*0.01/2,IF('Sheet1'!F22="Budget Surpassed",RANDBETWEEN('Sheet2'!D40,'Sheet2'!D41)*2*0.01,IF('Sheet1'!F16="Budget Exceeded",RANDBETWEEN('Sheet2'!D40,'Sheet2'!D41)*0.01))))))),"Not Applicable")
Here is what I have:
VBA Code:
If Sheets("Sheet1").Range("F16") = "Missed Budget" then
Sheets("My worksheet").Range("A33") = 0
end if
If Sheets("Sheet2").Range("C23") = "" and Sheets("Sheet2").Range("C22") = "Unknown" then
Sheets("My worksheet").Range("A33") = "Percentage of Budget"
end if
If Sheets("Sheet1").Range("F16") = "Hit Budget" and Sheets("Sheet2").Range("C20") = "1" and Sheets("My worksheet").Range("E26") = "Success" then
Sheets("My worksheet").Range("A33") = WorksheetFunction.RandBetween(Sheets("Sheet2").Range("D40"), Sheets("Sheet2").Range("D41")) * 0.01 / 2
end if
Etc..
Is there a more streamlined code for this? I'm mostly having trouble with applying the IFERROR part across the VBA Code and the MIN function.