Forum Discussion
VBA to output Product of two cells if checkbox is "Checked" but stay a zero value if "Unchecked"
- Nov 19, 2022
Rashaud35 it doesn't matter where the checkbox is located. you want to link to some 'other' cell and not the one you want the formula in. so in the attached I changed the 1st row to be 'linked' to D7 so in E7 is the formula =B7*C7*D7
You can then "hide" the true/false text by changing the font color to be same as fill color (you could also use custom number formatting if needed)
B) the macro call out shouldn't matter if you delete the display name. so if you right click and say edit text and delete all the text and then right click and say assign macro it will still say CheckBox1_Click because the check box is still named that but the label (display) is removed.
- Rashaud35Nov 19, 2022Copper Contributor
mtarlerThank you so much for helping me, I greatly appreciate it. However, it still does not seem to work. If cell D7 that contains the checkbox is checked, then the "linked" cell (E7) continues to be TRUE or FALSE and does not keep "=D7*C7*B7" inside the cell once checked. I think that's why I was assuming a Macro would work here. I've attached an example spreadsheet to show what's going on. When the box is checked, I'd like "FALSE" in cell E7 to be a Zero, but if "TRUE" I'd like the output to be Product of B7 times C7.
- mtarlerNov 19, 2022Silver Contributor
Rashaud35 it doesn't matter where the checkbox is located. you want to link to some 'other' cell and not the one you want the formula in. so in the attached I changed the 1st row to be 'linked' to D7 so in E7 is the formula =B7*C7*D7
You can then "hide" the true/false text by changing the font color to be same as fill color (you could also use custom number formatting if needed)
- Rashaud35Nov 19, 2022Copper Contributor
mtarler Ohhh okay, I see what you're saying now. I was missing the fact that True/False output needed to be in a totally different cell than the cell I wanted my output answer to be in. I can change the True/False font color (white) match the background of the cell so this will suffice. Thank you so much again!