2016-07-02 10 views
0

私は人々のTDEEを計算するのにHarris Benedict Equationを使用しています。私はGoogleシートを使ってこれに対応するフォームを作成していますが、Googleのシートは使い方が難しいです。私は数式解析エラーを取得しています。書式設定はそれほど残念です。複数のネストされたIFステートメントを使用したフィットネス計算機のデバッグ

私はどこか小さなカンマか括弧のエラーを作り出していることを知っていますが、どこがわからないのですか。

コードは、人々がメートル法/皇室法、男性/女性法、身長、体重、活動レベル、年齢を好むかどうかを尋ねることになっています。

googleシートはif statementsのようになります。それ

は - かなりのIF(A2 = "foo" という、 "A2はfooがある")(論理式、value_if_true、value_if_false)

=IF (D9=”Imperial”, 
    IF(D10=”Male”, 
      IF(D16=”Sedentary (no exercise)”, 
        66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.2, 

        IF(D16=”Lightly Active (1-3 days of exercise/week)”, 
          66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.375, 

          IF(D16=”Moderately Active (3-5 days of exercise/week)”, 
            66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.55, 

            IF(D16=”Very Active(6-7 days of exercise/week)”, 

              66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.725, 
              IF(D16=”Extremely Active(exercise twice a day)”, 

                66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.9, 
              “ “))))) 


      IF(D16=”Sedentary (no exercise)”, 
        655.1 + (4.35 x D14) + (4.7 x (D13x12+G13)) - (4.7 x D12) x1.2, 

          IF(Lightly Active (1-3 days of exercise/week)”, 
            655.1 + (4.35 x D14) + (4.7 x (D13x12+G13)) - (4.7 x D12) x1.375, 

            IF(Moderately Active (3-5 days of exercise/week)”, 
              655.1 + (4.35 x D14) + (4.7 x (D13x12+G13)) - (4.7 x D12) x1.55, 

              IF(D16=”Very Active(6-7 days of exercise/week)”, 
                655.1 + (4.35 x D14) + (4.7 x (D13x12+G13)) - (4.7 x D12) x1.725, 

                IF(D16=”Extremely Active(exercise twice a day)”, 
                  655.1 + (4.35 x D14) + (4.7 x (D13x12+G13)) - (4.7 x D12) x1.9, 
                “ “)))))) 


    IF(D10=”Male”, 
      IF(D16=”Sedentary (no exercise)”, 
        66.5 + (13.75 x D14) + (5.003 x D13) – (6.755 x D12)x1.2, 


        IF(Lightly Active (1-3 days of exercise/week)”, 
          66.5 + (13.75 x D14) + (5.003 x D13) – (6.755 x D12)x1.375, 


          IF(Moderately Active (3-5 days of exercise/week)”, 
            66.5 + (13.75 x D14) + (5.003 x D13) – (6.755 x D12)x1.55, 


            IF(D16=”Very Active(6-7 days of exercise/week)” 
              66.5 + (13.75 x D14) + (5.003 x D13) – (6.755 x D12)x1.725, 


              IF(D16=”Extremely Active(exercise twice a day)”, 

                66.5 + (13.75 x D14) + (5.003 x D13) – (6.755 x D12)x1.9, 

              “ “))))) 



      IF(D16=”Sedentary (no exercise)”, 
        655.1 + (9.563 x D14) + (1.850 x D13) – (4.676 x D12) x1.2, 


        IF(Lightly Active (1-3 days of exercise/week)”, 
          655.1 + (9.563 x D14) + (1.850 x D13) – (4.676 x D12) x1.375, 


          IF(Moderately Active (3-5 days of exercise/week)”, 
            655.1 + (9.563 x D14) + (1.850 x D13) – (4.676 x D12) x1.55, 


            IF(D16=”Very Active(6-7 days of exercise/week)”, 

              655.1 + (9.563 x D14) + (1.850 x D13) – (4.676 x D12) x1.725, 


              IF(D16=”Extremely Active(exercise twice a day)”, 

                655.1 + (9.563 x D14) + (1.850 x D13) – (4.676 x D12) x1.9, 

              “ “)))))) 

    ) 

答えて

2

あなたが持っている場合

構文は

です明らかに動作しないIF(Lightly Active (1-3 days of exercise/week)”のようなもの。 IFのこのような入れ子は最初にあってはいけません、それはタイプミスの地雷です。代わりにhlookupまたはvlookupを使用してください。 vlookup交換5つのネストされたIFの例:

=if(D9=”Imperial”, 
    if(D10=”Male”, 
    vlookup(D16, { 
     ”Sedentary (no exercise)”, 
     66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.2; 
     ”Lightly Active (1-3 days of exercise/week)”, 
     66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.375; 
     ”Moderately Active (3-5 days of exercise/week)”, 
     66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.55; 
     ”Very Active(6-7 days of exercise/week)”, 
     66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.725; 
     ”Extremely Active(exercise twice a day)”, 
     66 + (6.2 x D14) + (12.7 x (D13x12+G13)) – (6.76 x D12)x1.9, 
     }, 2, false) 
    .... 

あなたはここに15の代わりに5のオプションを置くことができます注意してください、そして新たな括弧が必要になります。 !あなたのデータが構成されている方法に応じて

、あなたはシートの別の場所でこの参照テーブルを置くことができるかもしれ、表A1に言う:B5、表A6:!B11、など:

=if(D9=”Imperial”, 
    if(D10=”Male”, 
    vlookup(D16, Table!A1:B5, 2, false), 
    vlookup(D16, Table!A6:B11, 2, false) 
    ), 
    if(D10=”Male”, 
    vlookup(D16, Table!A12:B16, 2, false), 
    vlookup(D16, Table!A17:B21, 2, false) 
    ) 
    ) 

ワンvlookupをそれぞれiferrorにラップすることができます。その結果、入力データが予想通りでない場合、#N/Aの代わりに空白の出力が得られます。エラー(後者はより有益であるが)。

関連する問題