Macro vba to assgin a formula to the variable

Minato5972

New Member
Joined
Mar 18, 2021
Messages
11
Office Version
  1. 2019
  2. 2016
Transformed(PRow * (c - 1) + 1, 39) = "=MAX(X" & Sum & ",Y" & Sum & ")-INDIRECT(ADDRESS(ROW(AC" & Sum + 3 & "), 28+X" & Sum + 1 & "))+ INDIRECT(ADDRESS(ROW(AF" & Sum & "), 28+(X" & Sum + 1 & "+1)))"

Value 0 must be assigned to "Transformed(PRow * (c - 1) + 1, 39) " if the value is negative.

So i tried to assign the formula to a vairably "qty" to check if the value is less than 0 by using a IF statement but worksheet.Evaluate("formula") is not working
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
And when you divids the formula in three pieces:
evaluate("=MAX(X" & Sum & ",Y" & Sum & ")")-evaluate("=INDIRECT(ADDRESS(ROW(AC" & Sum + 3 & "), 28+X" & Sum + 1 & "))")+evaluate("=INDIRECT(ADDRESS(ROW(AF" & Sum & "), 28+(X" & Sum + 1 & "+1)))")
 
Upvote 0
Solution
Thanks a lot but i dont know if it worked because the columns above equation is using have formulas in them. If you can split these two i will learn from them

"=MAX(Y" & Sum + 2 & ", IF(H" & Sum & "= 99,I" & Sum & ",SUM(OFFSET(H" & Sum - 1 & ",1,12,1,-H" & Sum & "),Y" & Sum + 3 & ")/H" & Sum & ")) "
"=IF(H" & Sum & "= 6,(SUM(P" & Sum & ":T" & Sum & ")+AC" & Sum & ")/H" & Sum & ",(SUM(S" & Sum & ":T" & Sum & ")+AC" & Sum & ")/H" & Sum & ")"

Thanks a lot once again
 
Upvote 0
Sorry, I don't mean the real formula in the cell but the formula to evaluate in VBA. The formula is to "big" for one evaluate function. But with three it is working.
qty=evaluate("=MAX(X" & Sum & ",Y" & Sum & ")")-evaluate("=INDIRECT(ADDRESS(ROW(AC" & Sum + 3 & "), 28+X" & Sum + 1 & "))")+evaluate("=INDIRECT(ADDRESS(ROW(AF" & Sum & "), 28+(X" & Sum + 1 & "+1)))")
 
Upvote 0
No i mean in that formula "X & sum" depends on some other formula (it has its own) so thats the reason i cant get it working
 
Upvote 0
If "sum" is a range name you can refer with: [sum]
 
Upvote 0
An other approach:
VBA Code:
Transformed(PRow * (c - 1) + 1, 39)= "=MAX(X" & Sum & ",Y" & Sum & ")-INDIRECT(ADDRESS(ROW(AC" & Sum + 3 & "), 28+X" & Sum + 1 & "))+ INDIRECT(ADDRESS(ROW(AF" & Sum & "), 28+(X" & Sum + 1 & "+1)))"
Transformed(PRow * (c - 1) + 1, 39)=IIF(Transformed(PRow * (c - 1) + 1, 39).Value<0,0,"=MAX(X" & Sum & ",Y" & Sum & ")-INDIRECT(ADDRESS(ROW(AC" & Sum + 3 & "), 28+X" & Sum + 1 & "))+ INDIRECT(ADDRESS(ROW(AF" & Sum & "), 28+(X" & Sum + 1 & "+1)))"
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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