I need to write a script in VBA so that if column B has a x (or just is filled) then goto the cell to the le开发者_开发问答ft of it and get the value, I want to do this on a worksheet and I want to be able to calculate the total cost of a project depending if its required.
I would run this on event of a button click, so I want it to get all the values, add them up, and display me the total, But ONLY for the values with a x (in column B).
Here is the formula you need:
=SUMIF(B:B,"=x",A:A)
which you can use in VBA this way:
Range("D7") = WorksheetFunction.SumIf(Range("B:B"), "=x", Range("A:A"))
精彩评论