VB函数不会进入循环(Excel)

时间:2016-02-01 08:59:44

标签: excel vba excel-vba

我正在开发一个Excel项目,我需要导入每月.csv文件,解析这些文件中的列并将相邻列中的数字返回到摘要表中。这是个主意:

  1. 读取列以解析为VB数组
  2. 连接要搜索的字符串,将其放入变量
  3. 在数组中搜索此变量
  4. 如果找到,请将1写入第二个数组(名为arrTrueFalse
  5. 如果找不到,请将0写入arrTrueFalse
  6. 完成后,将true / false数组与第三个数组相乘(范围从.csv到数量)基本上对它们进行SUMPRODUCT
  7. 这是代码,我会尝试标记它破坏的地方

    Private strBaba As String
    Private arrCampaigns() As Variant
    Private arrAmounts() As Variant
    Private arrTrueFalse() As Variant
    
    Public Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
        IsInArray = Not IsError(Application.Match(stringToBeFound, arr, 0)) 
    End Function
    
    Public Sub stringComparison()
        Dim i As Long, j As Long
    
        j = 1
    
        Call OptimizeCode_Begin
    
        With Sheet14
            arrCampaigns = .Range("F2:F1000").Value
            arrAmounts = .Range("I2:I1000").Value
        End With
    
        ReDim arrTrueFalse(1 To UBound(arrCampaigns) - LBound(arrCampaigns) + 1, 1 To 1)
    
        For i = 2 To Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Row
            strBaba = Sheet2.Range("A" & i).Value & "*" & Sheet2.Range("C" & i).Value & "*"
    
            Call IsInArray(strBaba, arrCampaigns)
    
            '=> Works up to this line (where I call IsInArray); after that, loop never gets executed?
    
            If IsInArray(strBaba, arrCampaigns) = True Then
                arrTrueFalse(j) = 1
            Else
                arrTrueFalse(j) = 0
            End If
    
            j = j + 1
        Next i
    
        Call OptimizeCode_End
    End Sub
    

    我做错了什么?

0 个答案:

没有答案