运行时错误1004范围公式

时间:2015-10-19 14:10:33

标签: excel vba excel-vba

我今天下午尝试编译一个宏,但我遇到了运行时错误:

  

应用程序定义或对象定义的错误。

这是我的代码:

Sub MajPO()


Dim i As Integer

Dim FromRStart, FromREnd, ToRStart, ToREnd
Dim Technology(18) As String
Technology(0) = "ADSL"
Technology(1) = "ADTRAN"
Technology(2) = "ADVA"
Technology(3) = "AGW HUAWEI"
Technology(4) = "CISCO"
Technology(5) = "CSI DWDM HUAWEI"
Technology(6) = "IP & IP/VPN REPAIR"
Technology(7) = "JUNIPER"
Technology(8) = "MEGAPAC"
Technology(9) = "MICROWAVE HUAWEI"
Technology(10) = "POWER"
Technology(11) = "ROP HOUSING"
Technology(12) = "SDH ERICSSON"
Technology(13) = "SDH MARCONI"
Technology(14) = "SOP14XX"
Technology(15) = "SYNCRO-GILLAM"
Technology(16) = "VDSL1"
Technology(17) = "VDSL2"

For i = 0 To 18
  Worksheets("FromRepair").Activate
    FromRStart = Application.Match(Technology(i), Range("A:A"), 0)
    FromREnd = Application.Match(Technology(i) & " Total", Range("A:A"), 0)
Worksheets("MissingPO").Activate
    ToRStart = Application.Match(Technology(i), Range("A:A"), 0)
    ToREnd = Application.Match(Technology(i) & " Total", Range("A:A"), 0)

myRange = ("K" & FromRStart & ":L" & FromREnd)
Range("O" & ToRStart).Formula = "=IFNA(VLOOKUP(B6;FromRepair!" & myRange & ";11;0)"

Next



End Sub

错误在以下行中:

Range("O" & ToRStart).Formula = "=IFNA(VLOOKUP(B6;FromRepair!" & myRange & ";11;0)"

你们中有谁知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

正如@Vamsi所说,你的公式中缺少一个结束括号。

此外,我还补充说,如果您想要完全匹配或近似匹配,则未在VLOOKUP中指定。由于此参数默认设置为近似,我建议您养成将其设置为符合您目的的习惯。

所以我建议这样做:

Range("O" & ToRStart).Formula = "=IFNA(VLOOKUP(B6,FromRepair!" & myRange & ",11,FALSE),0)"

答案 1 :(得分:0)

正如@Vasmi所说,我的公式中缺少括号,因此决议是:

Range("O" & ToRStart).Formula = "=IFNA(VLOOKUP(B6,FromRepair!" & myRange & ",11,FALSE),0)"

而不是

Range("O" & ToRStart).Formula = "=IFNA(VLOOKUP(B6,FromRepair!" & myRange & ",11,FALSE)