2016-07-02 10 views
0

Ich benutze die Harris Benedict Equation, um Leute TDEE berechnen. Ich verwende Google Tabellen, um eine Art Formular dafür zu erstellen, aber mit Google Tabellen ist es schwierig, damit zu arbeiten. Ich erhalte einen Formelanalysefehler. Die Formatierung ist ziemlich schlecht, tut mir leid.Debuggen eines Fitness-Rechners mit mehreren verschachtelten IF-Anweisungen

Ich weiß, dass ich einen kleinen Komma oder Klammerfehler irgendwo mache, aber ich bin mir nicht sicher, wo.

Der Code soll fragen, ob Menschen metrisch/imperial, männlich/weiblich, Größe, Gewicht, Aktivitätsgrad und Alter bevorzugen.

So funktioniert google sheets if statements. Es ziemlich is-

IF (A2 = "foo", "A2 ist foo")

Syntax ist

IF (logical_expression, Dann_Wert, Sonst_Wert)

=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, 

              “ “)))))) 

    ) 

Antwort

2

Sie haben Dinge wie IF(Lightly Active (1-3 days of exercise/week)”, die offensichtlich nicht funktionieren werden. Diese Art der Verschachtelung von IFs sollte nicht an erster Stelle stehen, es ist ein Minenfeld von Tippfehlern. Verwenden Sie stattdessen hlookup oder vlookup. Beispiel für vlookup ersetzt fünf verschachtelte IFs:

=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) 
    .... 

Beachten Sie, dass 15 statt 5 Optionen hier setzen können und keine neuen Klammern benötigt werden.

Je nachdem, wie Ihre Daten strukturiert ist, Sie in der Lage sein können, diese Referenztabellen in dem Blatt an anderer Stelle zu setzen, sagt in der Tabelle A1: B5, Tabelle A6: B11, etc:

=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) 
    ) 
    ) 

One kann jede vlookup in iferror so wickeln, dass, wenn die Eingabedaten nicht von der erwarteten Art sind, Sie leere Ausgabe anstelle von # N/A erhalten! Fehler (obwohl letzteres informativer ist).