将值分配给数组时,类型不匹配错误

时间:2019-10-07 14:38:46

标签: excel vba

我希望根据所选的特定商家遍历一组细分。

当代码到达以下部分时,就会出现我的问题:

For j = 0 To merchantArraySize
out(j) = outnames(j).Value
Next j

这将引发类型不匹配错误。奇怪的是,当在监视窗口中查看时,正确的值已分配给out和outnames,只是不允许我将整个数组发送到目的地。

Sub compute_merchant_segment_summary()

    Application.Calculation = xlCalculationAutomatic

    Dim program_range As Range
    Dim fico_range As Range
    Dim term_range As Range
    Dim band_range As Range

    Dim program_type As Range
    Dim fico_type As Range
    Dim term_type As Range
    Dim band_type As Range

    Dim i As Integer
    Dim j As Integer
    Dim out() As Long


    outnames = Array([I_LOAN_CODE], ..... 'total of 138 variables here)

    Dim merchantArraySize As Integer
    merchantArraySize = UBound(outnames) - LBound(outnames)

Set program_range =  Worksheets("Merchants").Range(Worksheets("Summary").Range("Merchant_Selection") & "_PROG")

    For Each program_type In program_range
        ReDim out(merchantArraySize)
        program_type.Copy
        Worksheets("Summary").Range("Program_Selection").Value = program_type
        Set term_range = Worksheets("Merchants").Range(Worksheets("Summary").Range("Merchant_Selection") & "_" & Worksheets("Summary").Range("term_new") & "_TERM")
        Set fico_range = Worksheets("Merchants").Range(Worksheets("Summary").Range("Merchant_Selection") & "_FICO")
        Set band_range = Worksheets("Merchants").Range(Worksheets("Summary").Range("Merchant_Selection") & "_BAND_SIZE")

            For Each term_type In term_range
                term_type.Copy
                Worksheets("Summary").Range("Term_Selection").Value = term_type

                    For Each fico_type In fico_range
                        fico_type.Copy
                        Worksheets("Summary").Range("FICO_Selection").Value = fico_type

                            For Each band_type In band_range
                                band_type.Copy
                                Worksheets("Summary").Range("Band_Selection").Value = band_type

                                    For j = 0 To merchantArraySize
                                        out(j) = outnames(j).Value
                                    Next j

                                    Worksheets("Loan Level").Activate
                                    Worksheets("Loan Level").Range(Cells(i + 1, 0), Cells(i + 1, 0 + merchantArraySize)) = out

                            Next band_type

                    Next fico_type

            Next term_type

    Next program_type
    End

End Sub

0 个答案:

没有答案