修改后编译错误

时间:2017-04-03 09:12:48

标签: excel vba excel-vba

我正在尝试修改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]"

问题在于逻辑正在看的值是时间(HHMM),它取右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只是不接受代码说这是编译错误!

1 个答案:

答案 0 :(得分: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]"