2017-04-03 97 views
0

我試圖修改一個spreadhseet,因爲它似乎最終會出現一些錯誤。下面 的代碼是當前之一:修改後編譯錯誤

Range("DP2").Value = "=IF(RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)<0,60+RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2),RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)) + RC[-1]" 

的問題是,該邏輯在看的值是時間(小時,分鐘),它需要正確的2(MM)和從另一時間減去(MM),如果價值低於零,它只是增加60,假設第一次提前一小時(這是事實),但問題是我觀察到差異超過一小時(2小時,3小時等)例如1110和0830,因此只加60就不會做正確的計算。 我寫這段代碼:

IF(RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)<=0, IF(LEFT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-LEFT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)=1,60+RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2), IF(LEFT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-LEFT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)=2,120+RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2), IF(LEFT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-LEFT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)=3,180+RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2),RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2))))) + RC[-1]" 

這一個應該看(左2日,HH)的時間值的小時部分,並據此決定是否增加60,120或180 但VBA不會接受代碼,說這是一個編譯錯誤!

回答

0

你已經超過了VBE每行的字符數,打破了你的字符串在單獨的行,像這樣:

Range("D2").Value = "IF(RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]" & _ 
"=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)<=0, IF(LEFT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-LEFT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)=1,60+RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2), IF(LEFT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-LEFT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)=2,120+RIGHT(IF" & _ 
"(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP" & _ 
"(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2), IF(LEFT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-LEFT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2)=3,180+RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2),RIGHT(IF(R1C[-110]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-110],0)),2)-RIGHT(IF(R1C[-111]=RC7,VLOOKUP(RC4,Services!C1:C254,32,0),VLOOKUP(RC4,Services!C1:C254,146+R1C[-111],0)),2))" & _ 
"))) + RC[-1]" 
+0

非常感謝你,這已經解決了這個錯誤,但它引入了之前沒有發生的新錯誤(舊代碼)。 它說有一個不匹配,當我去調試它突出顯示: line_txt = line_txt&nd_str&「,」 我很驚訝,因爲這在前面的代碼工作正常。 – Mahmoud

+0

在這種情況下,您需要嘗試和調試問題,如果您沒有獲得任何地方,則需要單獨提問。 –

+0

噢好吧沒問題。 非常感謝! – Mahmoud