How to: Multiply only numbers that contain values higher than 0

eDarren

New Member
Joined
Sep 5, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
My example here is that I have a sequence of columns within a spreadsheet that data can be input into:

A B C D E F
Blank Blank 3 7 Blank 2

The data input into A, B C D E or F can vary, sometimes it may contain a value, sometimes it may not.

In Column G, I want to have a multiplication of all the values from A B C D E and F BUT only the cells that contain a number, and ignore the cells which do not contain a value (otherwise the answer is always 0 which is inaccurate). If all the columns had values higher than 0, the formula would be simply A x B x C x D x E x F but the formula needs to be able to adapt and change autonomously as sometimes the formula may end up being A X D x F or D x E x F.

I'm looking to utilise VBA for this - does anybody know how I can achieve this?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this:

Book1
ABCDEFGH
12566060
Sheet1
Cell Formulas
RangeFormula
G1G1=PRODUCT(IF(A1:F1="",1,A1:F1))
H1H1=PRODUCT(FILTER(A1:F1,A1:F1<>""))
 
Upvote 0
Try this:

Book1
ABCDEFGH
12566060
Sheet1
Cell Formulas
RangeFormula
G1G1=PRODUCT(IF(A1:F1="",1,A1:F1))
H1H1=PRODUCT(FILTER(A1:F1,A1:F1<>""))
That's worked well. I have noticed though it doesn't seem to like it if the data is spread across different columns throughout the sheet. For example, taking data from C2, P19, T12 and X11. It's not been a problem for me though, i've just re-modelled how the data is presented within the sheet to make sure that the columns which are part of this equation are linearly spread so I can add into the equation C2:H2, for example.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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