2015-11-03 20 views
0

我有三個如果功能,但我不希望他們互相排斥。VBA多功能如果沒有排除下一個

例子:

ReportArray(5, Mailcounter) = 1  
ReportArray(11, Mailcounter) = 0  
ReportArray(17, Mailcounter) = 1 

上面的例子應該包括四個第一.HTMLBody和最後四個.HTMLBody

代碼

 If ReportArray(5, Mailcounter) > 0 Then 
      .HTMLBody = .HTMLBody & "<p style='font-family:Calibri, sans-serif;font-size:18'><B><U>" & "3.2.3-3.2.4 Landscaping & Irrigation System" & "</U></B></p>" 
      .HTMLBody = .HTMLBody & "<ul><li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "You currently have " + "<U>" & ReportArray(3, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in ""3.2.3-3.2.4 Landscaping & Irrigation System"" out of " + "<U>" & ReportArray(5, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in Landscaping & Irrigation System as a total." & "</p></li>" 
      .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "With regards to our data, ""3.2.3-3.2.4 Landscaping & Irrigation System"" are supposed to have " + "<U>" & Format(ReportArray(7, Mailcounter), "0.0 %") & "</U>" & " of the total Landscaping & Irrigation System." & "</p></li>" 
      .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "We would therefore like you to confirm whether this is true - and if yes, allocate " & ReportArray(8, Mailcounter) & " to ""Landscaping & Irrigation System - SBTB"" in your input sheet." & "</p></li></ul>" 

     If ReportArray(11, Mailcounter) > 0 Then 
      .HTMLBody = .HTMLBody & "<p style='font-family:Calibri, sans-serif;font-size:18'><B><U>" & "3.2.11 Interior Plant and Tree Maintenance" & "</U></B></p>" 
      .HTMLBody = .HTMLBody & "<ul><li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "You currently have " + "<U>" & ReportArray(9, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in ""3.2.11 Interior Plant and Tree Maintenance"" out of " + "<U>" & ReportArray(11, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in Interior Plant and Tree Maintenance as a total." & "</p></li>" 
      .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "With regards to our data, ""3.2.11 Interior Plant and Tree Maintenance"" are supposed to have " + "<U>" & Format(ReportArray(12, Mailcounter), "0.0 %") & "</U>" & " of the total Interior Plant and Tree Maintenance." & "</p></li>" 
      .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "We would therefore like you to confirm whether this is true - and if yes, allocate " & ReportArray(13, Mailcounter) & " to ""Landscaping & Irrigation System - SBTB"" in your input sheet." & "</p></li></ul>" 

     If ReportArray(17, Mailcounter) > 0 Then 
      .HTMLBody = .HTMLBody & "<p style='font-family:Calibri, sans-serif;font-size:18'><B><U>" & "3.3.10 Interior Pest Control" & "</U></B></p>" 
      .HTMLBody = .HTMLBody & "<ul><li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "You currently have " + "<U>" & ReportArray(15, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in ""3.3.10 Interior Pest Control"" out of " + "<U>" & ReportArray(17, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in Interior Pest Control as a total." & "</p></li>" 
      .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "With regards to our data, ""3.3.10 Interior Pest Control"" are supposed to have " + "<U>" & Format(ReportArray(19, Mailcounter), "0.0 %") & "</U>" & " of the total Interior Pest Control." & "</p></li>" 
      .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "We would therefore like you to confirm whether this is true - and if yes, allocate " & ReportArray(20, Mailcounter) & " to ""Landscaping & Irrigation System - SBTB"" in your input sheet." & "</p></li>" 

     End If 
     End If 
     End If 

回答

3

你需要讓每一個if語句是擁有。如果在每個if之後移動結尾:

If ReportArray(5, Mailcounter) > 0 Then 
     .HTMLBody = .HTMLBody & "<p style='font-family:Calibri, sans-serif;font-size:18'><B><U>" & "3.2.3-3.2.4 Landscaping & Irrigation System" & "</U></B></p>" 
     .HTMLBody = .HTMLBody & "<ul><li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "You currently have " + "<U>" & ReportArray(3, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in ""3.2.3-3.2.4 Landscaping & Irrigation System"" out of " + "<U>" & ReportArray(5, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in Landscaping & Irrigation System as a total." & "</p></li>" 
     .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "With regards to our data, ""3.2.3-3.2.4 Landscaping & Irrigation System"" are supposed to have " + "<U>" & Format(ReportArray(7, Mailcounter), "0.0 %") & "</U>" & " of the total Landscaping & Irrigation System." & "</p></li>" 
     .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "We would therefore like you to confirm whether this is true - and if yes, allocate " & ReportArray(8, Mailcounter) & " to ""Landscaping & Irrigation System - SBTB"" in your input sheet." & "</p></li></ul>" 
    End If 
    If ReportArray(11, Mailcounter) > 0 Then 
     .HTMLBody = .HTMLBody & "<p style='font-family:Calibri, sans-serif;font-size:18'><B><U>" & "3.2.11 Interior Plant and Tree Maintenance" & "</U></B></p>" 
     .HTMLBody = .HTMLBody & "<ul><li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "You currently have " + "<U>" & ReportArray(9, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in ""3.2.11 Interior Plant and Tree Maintenance"" out of " + "<U>" & ReportArray(11, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in Interior Plant and Tree Maintenance as a total." & "</p></li>" 
     .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "With regards to our data, ""3.2.11 Interior Plant and Tree Maintenance"" are supposed to have " + "<U>" & Format(ReportArray(12, Mailcounter), "0.0 %") & "</U>" & " of the total Interior Plant and Tree Maintenance." & "</p></li>" 
     .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "We would therefore like you to confirm whether this is true - and if yes, allocate " & ReportArray(13, Mailcounter) & " to ""Landscaping & Irrigation System - SBTB"" in your input sheet." & "</p></li></ul>" 
    End If 
    If ReportArray(17, Mailcounter) > 0 Then 
     .HTMLBody = .HTMLBody & "<p style='font-family:Calibri, sans-serif;font-size:18'><B><U>" & "3.3.10 Interior Pest Control" & "</U></B></p>" 
     .HTMLBody = .HTMLBody & "<ul><li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "You currently have " + "<U>" & ReportArray(15, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in ""3.3.10 Interior Pest Control"" out of " + "<U>" & ReportArray(17, Mailcounter) & " " & CurrencySheet.Range("A" & CountryCurrency) & "</U>" + " in Interior Pest Control as a total." & "</p></li>" 
     .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "With regards to our data, ""3.3.10 Interior Pest Control"" are supposed to have " + "<U>" & Format(ReportArray(19, Mailcounter), "0.0 %") & "</U>" & " of the total Interior Pest Control." & "</p></li>" 
     .HTMLBody = .HTMLBody & "<li><p style='font-family:Calibri, sans-serif;font-size:16'>" & "We would therefore like you to confirm whether this is true - and if yes, allocate " & ReportArray(20, Mailcounter) & " to ""Landscaping & Irrigation System - SBTB"" in your input sheet." & "</p></li>" 
    End If 

這應該分別對待每個if語句。

+0

令人難以置信,我很確定我在一開始就試過,thx :) –

+0

@SebastianKoefoed如何將它標爲正確? –