从工作簿中获取有编译器错误的数据

时间:2019-06-12 15:18:20

标签: excel vba

编译器错误:结尾为无。我知道这是错误的,并且我的代码中有些地方没有正确调用它,导致混乱,但我找不到它。我只是想从sheet1中获取信息,以便以后使用。

Private Sub Worksheet_Change(ByVal Target As Range)

'Code for column B
Dim AffectedRange As Range
Set AffectedRange = Intersect(Target, Me.Range("B2:B" & Me.Rows.Count))

If Not AffectedRange Is Nothing Then
    Dim iCell As Range
    For Each iCell In AffectedRange.Cells

            If iCell.Value = vbNullString Then
            iCell.Formula = "=IFERROR(IF($I" & iCell.Row & "="""","""",VLOOKUP($I" & iCell.Row & ",'Raw Data'!$A$1:$AH$5000,4,FALSE)),""N/A"")"
        End If
    Next iCell
End If

'Code for column D
Dim AffectedRange1 As Range
Set AffectedRange1 = Intersect(Target, Me.Range("D2:D" & Me.Rows.Count))

If Not AffectedRange1 Is Nothing Then
    Dim iCell1 As Range
    For Each iCell1 In AffectedRange1.Cells

            If iCell1.Value = vbNullString Then
            iCell1.Formula = "=IFERROR(IF($I" & iCell1.Row & "="""","""",IF(VLOOKUP($I" & iCell1.Row & ",'Raw Data'!$A$1:$AH$5000,9,FALSE)=0,""N/A"",VLOOKUP($I" & iCell1.Row & ", 'Raw Data'!$A$1:$AH$5000,9,FALSE))),""N/A"")"
        End If
    Next iCell1
End If

'Code for column E
Dim AffectedRange2 As Range
Set AffectedRange2 = Intersect(Target, Me.Range("E2:E" & Me.Rows.Count))

If Not AffectedRange2 Is Nothing Then
    Dim iCell2 As Range
    For Each iCell2 In AffectedRange2.Cells

            If iCell2.Value = vbNullString Then
            iCell2.Formula = "=IFERROR(IF($I" & iCell2.Row & "="""","""",IF(VLOOKUP($I" & iCell2.Row & ",'Raw Data'!$A$1:$AH$5000,10,FALSE)=0,""N/A"",VLOOKUP($I" & iCell2.Row & ", 'Raw Data'!$A$1:$AH$5000,10,FALSE))),""N/A"")"
        End If
    Next iCell2
End If

'Code for column C
Dim AffectedRange4 As Range
Set AffectedRange4 = Intersect(Target, Me.Range("C2:C" & Me.Rows.Count))

If Not AffectedRange4 Is Nothing Then
    Dim iCell4 As Range
    For Each iCell4 In AffectedRange4.Cells

            If iCell4.Value = vbNullString Then
            iCell4.Formula = "=IFERROR(IF($I" & iCell4.Row & "="""","""",IF(VLOOKUP($I" & iCell4.Row & ",'Raw Data'!A$1:$AH$5000,22,FALSE)=0,""N/A"",IF(VLOOKUP($I" & iCell4.Row & ",'Raw Data'!A$1:$AH$5000,22,FALSE)<0.49999,""Prio 3"",IF(AND(VLOOKUP($I" & iCell4.Row & ",'Raw Data'!A$1:$AH$5000,22,FALSE)>0.49999,VLOOKUP($I" & iCell4.Row & ",'Raw Data'!A$1:$AH$5000,22,FALSE)<0.79999),""Prio 2"",IF(VLOOKUP($I" & iCell4.Row & ",'Raw Data'!A$1:$AH$5000,22,FALSE)>0.79999,""Prio 1"",""N/A""))))),""N/A"")"
        End If
    Next iCell4
End If

'Code for column H
Dim AffectedRange5 As Range
Set AffectedRange5 = Intersect(Target, Me.Range("H2:H" & Me.Rows.Count))

If Not AffectedRange5 Is Nothing Then
    Dim iCell5 As Range
    For Each iCell5 In AffectedRange5.Cells

            If iCell5.Value = vbNullString Then
            iCell5.Formula = "=IFERROR(IF($I" & iCell5.Row & "="""","""",IF(VLOOKUP($I" & iCell5.Row & ",'Raw Data'!$A$1:$AH$5000,11,FALSE)=0,""N/A"",VLOOKUP($I" & iCell5.Row & ", 'Raw Data'!$A$1:$AH$5000,11,FALSE))),""N/A"")"
        End If
    Next iCell5
End If

'Code for column F
Dim AffectedRange6 As Range
Set AffectedRange6 = Intersect(Target, Me.Range("F2:F" & Me.Rows.Count))

If Not AffectedRange6 Is Nothing Then
    Dim iCell6 As Range
    For Each iCell6 In AffectedRange6.Cells

            If iCell6.Value = vbNullString Then
            iCell6.Formula = "=IFERROR(IF($I" & iCell6.Row & "="""","""",(IF(OR($D" & iCell6.Row & "=""N/A"",$D" & iCell6.Row & "=""""),""N/A"",IF(AND($H" & iCell6.Row & "=""Espagne"",LEN($D" & iCell6.Row & ")=5),VLOOKUP(LEFT($D" & iCell6.Row & ",2),Regionslist!$A$1:$B$52,2,FALSE),IF(AND($H" & iCell6.Row & "=""Espagne"",LEN($D" & iCell6.Row & ")=4),VLOOKUP(""0""&LEFT($D" & iCell6.Row & ",1),Regionslist!$A$1:$B$52,2,FALSE),$H" & iCell6.Row & "))))),$H" & iCell6.Row & ")"
        End If
    Next iCell6
End If

'Code for column G
Dim AffectedRange7 As Range
Set AffectedRange7 = Intersect(Target, Me.Range("G2:G" & Me.Rows.Count))

If Not AffectedRange7 Is Nothing Then
    Dim iCell7 As Range
    For Each iCell7 In AffectedRange7.Cells

            If iCell7.Value = vbNullString Then
            iCell7.Formula = "=IFERROR(IF($I" & iCell7.Row & "="""","""",VLOOKUP($F" & iCell7.Row & ",Regionslist!$B$1:$C$52,2,FALSE)),$F" & iCell7.Row & ")"
        End If
    Next iCell7
End If

'Code for column J
Dim AffectedRange8 As Range
Set AffectedRange8 = Intersect(Target, Me.Range("J2:J" & Me.Rows.Count))

If Not AffectedRange8 Is Nothing Then
    Dim iCell8 As Range
    For Each iCell8 In AffectedRange8.Cells

            If iCell8.Value = vbNullString Then
            iCell8.Formula = "=IFERROR(IF($I" & iCell8.Row & "="""","""",VLOOKUP($I" & iCell8.Row & ",'Raw Data'!$A$1:$AH$5000,2,FALSE)),""N/A"")"
        End If
    Next iCell8
End If

'Code for column K
Dim AffectedRange9 As Range
Set AffectedRange9 = Intersect(Target, Me.Range("K2:K" & Me.Rows.Count))

If Not AffectedRange9 Is Nothing Then
    Dim iCell9 As Range
    For Each iCell9 In AffectedRange9.Cells

            If iCell9.Value = vbNullString Then
            iCell9.Formula = "=IFERROR(IF($I" & iCell9.Row & "="""","""",IF(SUBSTITUTE(VLOOKUP($I" & iCell9.Row & ",'Raw Data'!$A$1:$AH$5000,13,FALSE),"","","""")<>"""",SUBSTITUTE(VLOOKUP($I" & iCell9.Row & ",'Raw Data'!$A$1:$AH$5000,13,FALSE),"","",""""),""N/A"")),""N/A"")"
        End If
    Next iCell9
End If

'Code for column L
Dim AffectedRange10 As Range
Set AffectedRange10 = Intersect(Target, Me.Range("L2:L" & Me.Rows.Count))

If Not AffectedRange10 Is Nothing Then
    Dim iCell10 As Range
    For Each iCell10 In AffectedRange10.Cells

            If iCell10.Value = vbNullString Then
            iCell10.Formula = "=IFERROR(IF($I" & iCell10.Row & "="""","""",SUBSTITUTE(VLOOKUP($I" & iCell10.Row & ",'Raw Data'!$A$1:$AH$5000,20,FALSE),"","","""")),""N/A"")"
        End If
    Next iCell10
End If

'Code for column M
Dim AffectedRange11 As Range
Set AffectedRange11 = Intersect(Target, Me.Range("M2:M" & Me.Rows.Count))

If Not AffectedRange11 Is Nothing Then
    Dim iCell11 As Range
    For Each iCell11 In AffectedRange11.Cells

            If iCell11.Value = vbNullString Then
            iCell11.Formula = "=IFERROR(IF($I" & iCell11.Row & "="""","""",VLOOKUP($I" & iCell11.Row & ",'Raw Data'!$A$1:$AH$5000,22,FALSE)),""N/A"")"
        End If
    Next iCell11
End If

'Code for column N
Dim AffectedRange12 As Range
Set AffectedRange12 = Intersect(Target, Me.Range("N2:N" & Me.Rows.Count))

If Not AffectedRange12 Is Nothing Then
    Dim iCell12 As Range
    For Each iCell12 In AffectedRange12.Cells

            If iCell12.Value = vbNullString Then
            iCell12.Formula = "=IFERROR(IF($I" & iCell12.Row & "="""","""",""1.""&VLOOKUP($I" & iCell12.Row & ",'Raw Data'!$A$1:$AH$5000,21,FALSE)),""N/A"")"
        End If
    Next iCell12
End If

'Code for column W
Dim AffectedRange13 As Range
Set AffectedRange13 = Intersect(Target, Me.Range("W2:W" & Me.Rows.Count))

If Not AffectedRange13 Is Nothing Then
    Dim iCell13 As Range
    For Each iCell13 In AffectedRange13.Cells

            If iCell13.Value = vbNullString Then
            iCell13.Formula = "=IF($I" & iCell13.Row & "="""","""",IFERROR(IF(VLOOKUP($I" & iCell13.Row & ",'Raw Data'!$A$1:$AH$5000,1,FALSE)=$I" & iCell13.Row & ",""yes"",""no""),""no""))"
        End If
    Next iCell13
End If
End sub

编译器错误:结尾为不包含

0 个答案:

没有答案