Need help condensing an IF Statement

ceytl

Board Regular
Joined
Jun 6, 2009
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
Is there an easier way to write this formula?

=IF(A1="US",(B1<>"")*100,(B1<>"")*150)+IF(A1="US",(C1<>"")*225,(C1<>"")*275)+IF(A1="US",(D1<>"")*50,(D1<>"")*90)+IF(A1="US",(E1<>"")*400,(E1<>"")*425)

Also, instead of using <>"", I would like it to only show the value if there is 9 digits inside the reference cell, like: 522789333, but I'm not sure if that is possible?

Thanks!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Could you give us 5-6 rows of sample data and expected results with XL2BB? That might clear up things like whether columns B:E get filled from the left or whether they can contain values randomly or whether there is only 1 value in those columns in each row, whether the data is numerical or text etc. You are very familiar with your data, but we have no idea. :)

Could you also update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

1590894058574.png
 
Upvote 0
Could you give us 5-6 rows of sample data and expected results with XL2BB? That might clear up things like whether columns B:E get filled from the left or whether they can contain values randomly or whether there is only 1 value in those columns in each row, whether the data is numerical or text etc. You are very familiar with your data, but we have no idea. :)

Could you also update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

View attachment 15135

Here's the data:

Test.xlsx
H
25
Sheet1


Sorry, my spreadsheet is more detailed than my original post.

I am trying to see if there's an easier way to write the formula, so I don't have 12 IF Statements.

Instead of using <>"" in my reference cells, is there a way to have a cell return the value with only 9 digits in it?

Currently all cells are blank or only have 9 numbers in them.

Thanks for your help!
 
Upvote 0
Sorry, I didn't post the data correctly:

Test.xlsx
ABCDEFGHIJKLMNOPQ
1BracketBG 100BG 200BG 300MG 100MG 200FG 100HG 100HG 200HG 300HTG 100HTG 200RMG 500 Total Bracket 1 - 3Bracket 4 - 6
21 to 3440149018440149018440862815440614014440614021 $1,050.00 BG 100 $ 100.00 $ 200.00
34 to 6440840416440683129440840399 $ 800.00 BG 200 $ 150.00 $ 350.00
44 to 6440840423440614020440840421440862889440614013440613993 $2,000.00 BG 300 $ 200.00 $ 400.00
51 to 3440840413440700254440614005440700254 $1,000.00 MG 100 $ 250.00 $ 300.00
64 to 6440840428439468577 $ 550.00 MG 200 $ 350.00 $ 400.00
71 to 3440840358440840431 $ 550.00 FG 100 $ 50.00 $ 100.00
84 to 6440614022440683230 $ 550.00 HG 100 $ 100.00 $ 150.00
91 to 3440614009440840397 $ 400.00 HG 200 $ 200.00 $ 250.00
101 to 3440840360914154596 $ 400.00 HG 300 $ 300.00 $ 400.00
111 to 3439468577 $ 200.00 HTG 100 $ 500.00 $ 600.00
124 to 6440862820440840431 $ 700.00 HTG 200 $ 400.00 $ 450.00
134 to 6981233745440140351 $ 750.00 RMG 500 $ 300.00 $ 350.00
Sheet1
Cell Formulas
RangeFormula
N2:N13N2=IF($A2="1 to 3",($B2<>"")*$P$2,($B2<>"")*$Q$2)+IF($A2="1 to 3",($C2<>"")*$P$3,($C2<>"")*$Q$3)+IF($A2="1 to 3",($D2<>"")*$P$4,($D2<>"")*$Q$4)+IF($A2="1 to 3",($E2<>"")*$P$5,($E2<>"")*$Q$5)+IF($A2="1 to 3",($F2<>"")*$P$6,($F2<>"")*$Q$6)+IF($A2="1 to 3",($G2<>"")*$P$7,($G2<>"")*$Q$7)+IF($A2="1 to 3",($H2<>"")*$P$8,($H2<>"")*$Q$8)+IF($A2="1 to 3",($I2<>"")*$P$9,($I2<>"")*$Q$9)+IF($A2="1 to 3",($J2<>"")*$P$10,($J2<>"")*$Q$10)+IF($A2="1 to 3",($K2<>"")*$P$11,($K2<>"")*$Q$11)+IF($A2="1 to 3",($L2<>"")*$P$12,($L2<>"")*$Q$12)+IF($A2="1 to 3",($M2<>"")*$P$13,($M2<>"")*$Q$13)
 
Upvote 0
Sorry, my spreadsheet is more detailed than my original post.
Which is why we needed to know about it. ;)

See if this, copied down, does what you want.

20 05 31.xlsm
ABCDEFGHIJKLMNOPQ
1BracketBG 100BG 200BG 300MG 100MG 200FG 100HG 100HG 200HG 300HTG 100HTG 200RMG 500 Total Bracket 1 - 3Bracket 4 - 6
21 to 34401490184401490184408628154406140144406140211050BG 100100200
34 to 6440840416440683129440840399800BG 200150350
44 to 64408404234406140204408404214408628894406140134406139932000BG 300200400
51 to 34408404134407002544406140054407002541000MG 100250300
64 to 6440840428439468577550MG 200350400
71 to 3440840358440840431550FG 10050100
84 to 6440614022440683230550HG 100100150
91 to 3440614009440840397400HG 200200250
101 to 3440840360914154596400HG 300300400
111 to 3439468577200HTG 100500600
124 to 6440862820440840431700HTG 200400450
134 to 6981233745440140351750RMG 500300350
ceytl
Cell Formulas
RangeFormula
N2:N13N2=SUMPRODUCT(IF(A2="1 to 3",P$2:P$13,Q$2:Q$13)*TRANSPOSE(B2:M2<>""))
 
Upvote 0
Which is why we needed to know about it. ;)

See if this, copied down, does what you want.

20 05 31.xlsm
ABCDEFGHIJKLMNOPQ
1BracketBG 100BG 200BG 300MG 100MG 200FG 100HG 100HG 200HG 300HTG 100HTG 200RMG 500 Total Bracket 1 - 3Bracket 4 - 6
21 to 34401490184401490184408628154406140144406140211050BG 100100200
34 to 6440840416440683129440840399800BG 200150350
44 to 64408404234406140204408404214408628894406140134406139932000BG 300200400
51 to 34408404134407002544406140054407002541000MG 100250300
64 to 6440840428439468577550MG 200350400
71 to 3440840358440840431550FG 10050100
84 to 6440614022440683230550HG 100100150
91 to 3440614009440840397400HG 200200250
101 to 3440840360914154596400HG 300300400
111 to 3439468577200HTG 100500600
124 to 6440862820440840431700HTG 200400450
134 to 6981233745440140351750RMG 500300350
ceytl
Cell Formulas
RangeFormula
N2:N13N2=SUMPRODUCT(IF(A2="1 to 3",P$2:P$13,Q$2:Q$13)*TRANSPOSE(B2:M2<>""))


Thanks, it works great!

I have one more question, if I add a date column on every other column, how would you write the code so it doesn't add up the date column, but everything else?

Test.xlsx
DEFGHIJKLMNOPQRSTUVWXYZAAAB
1BG 200DateBG 300DateMG 100DateMG 200DateFG 100DateHG 100DateHG 200DateHG 300DateHTG 100DateHTG 200DateRMG 500 Total Bracket 1 - 3Bracket 4 - 6
24401490185/20/20205/20/20204401490185/20/20205/20/20204408628155/20/20204406140145/20/20205/20/20205/20/20204406140215/20/20205/20/2020#N/ABG 100 $ 100.00 $ 200.00
35/21/20205/21/20205/21/20205/21/20205/21/20205/21/20204406831295/21/20205/21/20205/21/20205/21/2020440840399#N/ABG 200 $ 150.00 $ 350.00
44408404235/22/20204406140205/22/20204408404215/22/20204408628895/22/20205/22/20204406140135/22/20205/22/20204406139935/22/20205/22/20205/22/2020#N/ABG 300 $ 200.00 $ 400.00
55/23/20205/23/20205/23/20204407002545/23/20204406140055/23/20205/23/20205/23/20205/23/20204407002545/23/20205/23/2020#N/AMG 100 $ 250.00 $ 300.00
65/24/20205/24/20204408404285/24/20205/24/20205/24/20205/24/20204394685775/24/20205/24/20205/24/20205/24/2020#N/AMG 200 $ 350.00 $ 400.00
74408403585/25/20205/25/20205/25/20205/25/20205/25/20205/25/20205/25/20205/25/20205/25/20204408404315/25/2020#N/AFG 100 $ 50.00 $ 100.00
85/26/20204406140225/26/20205/26/20205/26/20205/26/20204406832305/26/20205/26/20205/26/20205/26/20205/26/2020#N/AHG 100 $ 100.00 $ 150.00
95/27/20205/27/20205/27/20205/27/20205/27/20204406140095/27/20205/27/20205/27/20205/27/20205/27/2020440840397#N/AHG 200 $ 200.00 $ 250.00
105/28/20205/28/20205/28/20205/28/20205/28/20205/28/20205/28/20209141545965/28/20205/28/20205/28/2020#N/AHG 300 $ 300.00 $ 400.00
115/29/20205/29/20205/29/20205/29/20205/29/20205/29/20204394685775/29/20205/29/20205/29/20205/29/2020#N/AHTG 100 $ 500.00 $ 600.00
125/30/20205/30/20205/30/20205/30/20204408628205/30/20205/30/20205/30/20205/30/20204408404315/30/20205/30/2020#N/AHTG 200 $ 400.00 $ 450.00
139812337455/31/20205/31/20205/31/20204401403515/31/20205/31/20205/31/20205/31/20205/31/20205/31/20205/31/2020#N/ARMG 500 $ 300.00 $ 350.00
Sheet1
Cell Formulas
RangeFormula
Y2:Y13Y2=SUMPRODUCT(IF(A2="1 to 3",AA$2:AA$13,AB$2:AB$13)*TRANSPOSE(B2:X2<>""))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
if I add a date column on every other column, how would you write the code so it doesn't add up the date column, but everything else?
Try this

20 05 31.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1BracketBG 100DateBG 200DateBG 300DateMG 100DateMG 200DateFG 100DateHG 100DateHG 200DateHG 300DateHTG 100DateHTG 200DateRMG 500Date Total Bracket 1 - 3Bracket 4 - 6
21 to 35/05/20204401490185/05/20205/05/20204401490185/05/20205/05/20204408628155/05/20204406140145/05/20205/05/20205/05/20204406140215/05/20205/05/20205/05/20201050BG 100100200
34 to 64408404165/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204406831295/05/20205/05/20205/05/20205/05/20204408403995/05/2020800BG 200150350
44 to 65/05/20204408404235/05/20204406140205/05/20204408404215/05/20204408628895/05/20205/05/20204406140135/05/20205/05/20204406139935/05/20205/05/20205/05/20205/05/20202000BG 300200400
51 to 34408404135/05/20205/05/20205/05/20205/05/20204407002545/05/20204406140055/05/20205/05/20205/05/20205/05/20204407002545/05/20205/05/20205/05/20201000MG 100250300
64 to 65/05/20205/05/20205/05/20204408404285/05/20205/05/20205/05/20205/05/20204394685775/05/20205/05/20205/05/20205/05/20205/05/2020550MG 200350400
71 to 35/05/20204408403585/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204408404315/05/20205/05/2020550FG 10050100
84 to 65/05/20205/05/20204406140225/05/20205/05/20205/05/20205/05/20204406832305/05/20205/05/20205/05/20205/05/20205/05/20205/05/2020550HG 100100150
91 to 35/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204406140095/05/20205/05/20205/05/20205/05/20205/05/20204408403975/05/2020400HG 200200250
101 to 34408403605/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20209141545965/05/20205/05/20205/05/20205/05/2020400HG 300300400
111 to 35/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204394685775/05/20205/05/20205/05/20205/05/20205/05/2020200HTG 100500600
124 to 65/05/20205/05/20205/05/20205/05/20205/05/20204408628205/05/20205/05/20205/05/20205/05/20204408404315/05/20205/05/20205/05/2020700HTG 200400450
134 to 65/05/20209812337455/05/20205/05/20205/05/20204401403515/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/2020750RMG 500300350
ceytl (2)
Cell Formulas
RangeFormula
Z2:Z13Z2=SUMPRODUCT((B2:X2<>"")*IFERROR(VLOOKUP(B$1:X$1,AA$2:AC$13,2+(A2="4 to 6"),0),0))
 
Upvote 0
Try this

20 05 31.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1BracketBG 100DateBG 200DateBG 300DateMG 100DateMG 200DateFG 100DateHG 100DateHG 200DateHG 300DateHTG 100DateHTG 200DateRMG 500Date Total Bracket 1 - 3Bracket 4 - 6
21 to 35/05/20204401490185/05/20205/05/20204401490185/05/20205/05/20204408628155/05/20204406140145/05/20205/05/20205/05/20204406140215/05/20205/05/20205/05/20201050BG 100100200
34 to 64408404165/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204406831295/05/20205/05/20205/05/20205/05/20204408403995/05/2020800BG 200150350
44 to 65/05/20204408404235/05/20204406140205/05/20204408404215/05/20204408628895/05/20205/05/20204406140135/05/20205/05/20204406139935/05/20205/05/20205/05/20205/05/20202000BG 300200400
51 to 34408404135/05/20205/05/20205/05/20205/05/20204407002545/05/20204406140055/05/20205/05/20205/05/20205/05/20204407002545/05/20205/05/20205/05/20201000MG 100250300
64 to 65/05/20205/05/20205/05/20204408404285/05/20205/05/20205/05/20205/05/20204394685775/05/20205/05/20205/05/20205/05/20205/05/2020550MG 200350400
71 to 35/05/20204408403585/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204408404315/05/20205/05/2020550FG 10050100
84 to 65/05/20205/05/20204406140225/05/20205/05/20205/05/20205/05/20204406832305/05/20205/05/20205/05/20205/05/20205/05/20205/05/2020550HG 100100150
91 to 35/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204406140095/05/20205/05/20205/05/20205/05/20205/05/20204408403975/05/2020400HG 200200250
101 to 34408403605/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20209141545965/05/20205/05/20205/05/20205/05/2020400HG 300300400
111 to 35/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204394685775/05/20205/05/20205/05/20205/05/20205/05/2020200HTG 100500600
124 to 65/05/20205/05/20205/05/20205/05/20205/05/20204408628205/05/20205/05/20205/05/20205/05/20204408404315/05/20205/05/20205/05/2020700HTG 200400450
134 to 65/05/20209812337455/05/20205/05/20205/05/20204401403515/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/2020750RMG 500300350
ceytl (2)
Cell Formulas
RangeFormula
Z2:Z13Z2=SUMPRODUCT((B2:X2<>"")*IFERROR(VLOOKUP(B$1:X$1,AA$2:AC$13,2+(A2="4 to 6"),0),0))

Thanks for helping!

I am having a problem with the worksheet not totaling correctly. Row 2 should total $1,550, but it shows $1,050

I don't want the date columns to add, but it shows them adding as part of the total when I enter a date.

Thanks for all your help!
 
Upvote 0
Row 2 should total $1,550, but it shows $1,050
I think I might have had the Date columns on the wrong side of the other columns, corrected below. However, I still get 1,050 for row 2. As I understand the problem the formula for row 2 should sum the coloured values in column AB, which it does. I used your sample data from post #4 where your original formula also gave 1050. How/why do you now calculate 1550 for that row?

20 05 31.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1BracketDateBG 100DateBG 200DateBG 300DateMG 100DateMG 200DateFG 100DateHG 100DateHG 200DateHG 300DateHTG 100DateHTG 200DateRMG 500 Total Bracket 1 - 3Bracket 4 - 6
21 to 35/05/20205/05/20204401490185/05/20205/05/20204401490185/05/20205/05/20204408628155/05/20204406140145/05/20205/05/20205/05/20204406140215/05/20205/05/20201050BG 100100200
34 to 65/05/20204408404165/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204406831295/05/20205/05/20205/05/20205/05/2020440840399800BG 200150350
44 to 65/05/20205/05/20204408404235/05/20204406140205/05/20204408404215/05/20204408628895/05/20205/05/20204406140135/05/20205/05/20204406139935/05/20205/05/20205/05/20202000BG 300200400
51 to 35/05/20204408404135/05/20205/05/20205/05/20205/05/20204407002545/05/20204406140055/05/20205/05/20205/05/20205/05/20204407002545/05/20205/05/20201000MG 100250300
64 to 65/05/20205/05/20205/05/20205/05/20204408404285/05/20205/05/20205/05/20205/05/20204394685775/05/20205/05/20205/05/20205/05/2020550MG 200350400
71 to 35/05/20205/05/20204408403585/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204408404315/05/2020550FG 10050100
84 to 65/05/20205/05/20205/05/20204406140225/05/20205/05/20205/05/20205/05/20204406832305/05/20205/05/20205/05/20205/05/20205/05/2020550HG 100100150
91 to 35/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204406140095/05/20205/05/20205/05/20205/05/20205/05/2020440840397400HG 200200250
101 to 35/05/20204408403605/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20209141545965/05/20205/05/20205/05/2020400HG 300300400
111 to 35/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204394685775/05/20205/05/20205/05/20205/05/2020200HTG 100500600
124 to 65/05/20205/05/20205/05/20205/05/20205/05/20205/05/20204408628205/05/20205/05/20205/05/20205/05/20204408404315/05/20205/05/2020700HTG 200400450
134 to 65/05/20205/05/20209812337455/05/20205/05/20205/05/20204401403515/05/20205/05/20205/05/20205/05/20205/05/20205/05/20205/05/2020750RMG 500300350
ceytl (2)
Cell Formulas
RangeFormula
Z2:Z13Z2=SUMPRODUCT((B2:Y2<>"")*IFERROR(VLOOKUP(B$1:Y$1,AA$2:AC$13,2+(A2="4 to 6"),0),0))
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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