簡體   English   中英

為什么這段多行代碼會出現 VBA 語法錯誤?

[英]Why is there a VBA syntax error in this multi-line of code?

我有一行這么長的代碼。 VBE 說它有語法錯誤。 我檢查了代碼,我很確定它應該沒問題。 我是否超過了限制?

Worksheets("DTR").Cells(Total_Rows_Formulas + 1, 26) = "=IF(INDEX('Payroll Tables and Settings'!D$2:D$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))=""Extra"",0,IF(DTR!AI" & Total_Rows_Formulas + 1 & "=""Sunday"",IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""Regular"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0,INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0)),INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))+(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ") _
            +2*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*0.3*(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*1.3*1.3+(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*1.3*0.1),IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""SNWH"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0 _
            ,0,(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.5+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.5*1.3+(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.5*0.1),0)),IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""Regular"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0 _
            ,INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0)),INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))+(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*1.3 _
            +(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*0.1),IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""SNWH"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0,0,(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.3+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.3*1.3 _
            +(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.3*0.1),0))))"

嘗試以下語句,以確保在字符串文字中不會出現換行符:

Worksheets("DTR").Cells(Total_Rows_Formulas + 1, 26) = "=IF(INDEX('Payroll Tables and Settings'!D$2:D$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))=""Extra"",0,IF(DTR!AI" & Total_Rows_Formulas + 1 & "=""Sunday"",IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""Regular"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0,INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0)),INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))+(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")" & _
            "+2*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*0.3*(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*1.3*1.3+(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*1.3*0.1),IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""SNWH"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0" & _
            ",0,(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.5+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.5*1.3+(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.5*0.1),0)),IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""Regular"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0" & _
            ",INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0)),INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))+(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*1.3" & _
            "+(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*2*0.1),IF(IFERROR(INDEX('Holidays Table'!B$2:B$1048576,MATCH(DTR!C" & Total_Rows_Formulas + 1 & ",'Holidays Table'!A$2:A$1048576,0)),0)=""SNWH"",IF(SUM(DTR!P" & Total_Rows_Formulas + 1 & ":S" & Total_Rows_Formulas + 1 & ")=0,0,(DTR!P" & Total_Rows_Formulas + 1 & "+DTR!R" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.3+(DTR!Q" & Total_Rows_Formulas + 1 & "+DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.3*1.3" & _
            "+(DTR!R" & Total_Rows_Formulas + 1 & "+1.3*DTR!S" & Total_Rows_Formulas + 1 & ")*(INDEX('Payroll Tables and Settings'!B$2:B$1048576,MATCH(DTR!B" & Total_Rows_Formulas + 1 & ",'Payroll Tables and Settings'!A$2:A$1048576,0))/8)*1.3*0.1),0))))"

我不知道代碼是否會真正運行,但它至少繞過了語法錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM