简体   繁体   English

初始化阵列时出错*类型不匹配*

[英]Error Initializing Array *Type Mismatch*

Attempting to utilize two arrays to iterate through a data transfer process by copy and pasting cells from one sheet into a newly created one. 尝试通过将单元格中的单元格复制并粘贴到新创建的单元格中来利用两个数组来迭代数据传输过程。 The code below is merely responsible for copy and pasting the correct data in the correct order from one sheet to the newly created one. 下面的代码仅负责以正确的顺序从正确的顺序复制和粘贴正确的数据到新创建的数据。 I'm receiving a type mismatch when attempting to initialize the arrays. 尝试初始化数组时,我收到类型不匹配。 It occurs on the first array, but I haven't gotten to the second array to test that yet, so it could be wrong as well. 它发生在第一个数组上,但我还没有到第二个数组进行测试,所以它也可能是错误的。

Things to Note: 1) firmLocationColumn is of type long. 注意事项: 1)firmLocationColumn类型为long。 2) All the data stored in said arrays are meant to represent column numbers. 2)存储在所述阵列中的所有数据都用于表示列号。 They are out of order so I needed to store them in the array in the proper order so that it's easier to iterate through them rather than writing the same information over and over again. 它们是乱序的,所以我需要以正确的顺序将它们存储在数组中,以便更容易迭代它们而不是一遍又一遍地写入相同的信息。

Let me know if I missed anything that needs to be explained and i'll edit my question: 如果我错过了任何需要解释的内容,请告诉我,我会编辑我的问题:

Private Sub GetSpecificTradeDetails(ByVal masterListRow As Long, ByVal firmLocationColumn As Long, ByVal newExcelConfirmSheet As Worksheet, ByVal newExcelConfirmSheetLastRow As Long)

    Dim tradesMasterListColumnIndexArray() As Long
    Dim newExcelConfirmColumnIndexArray() As Long
    Dim arrayIndexCounter As Long

    'Sets array of columns for loop iteration through data sheet
    tradesMasterListColumnIndexArray() = [1,4,firmLocationColumn,(firmLocationColumn - 1),(firmLocationColumn + 3),15,16,10,11,8,19,18,17,(firmLocationColumn + 4),9,6,2]
    newExcelConfirmColumnIndexArray() = [1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18]

    Select Case firmLocationColumn

        Case 25

            'Sets confirm direction to "BUY"
            newExcelConfirmSheet.Cells((newExcelConfirmSheetLastRow + 1), 6) = "BUY"

        Case 27

            'Sets confirm direction to "SELL"
            newExcelConfirmSheet.Cells((newExcelConfirmSheetLastRow + 1), 6) = "SELL"

    End Select

    'Transfers trade details between the masterlist and the newly created confirm sheet
    With TradesMasterSheet

        For arrayIndexCounter = 0 To 17

            .Cells(masterListRow, tradesMasterListColumnIndexArray(arrayIndexCounter)).Copy _
                Destination:=newExcelConfirmSheet.Cells((newExcelConfirmSheetLastRow + 1), newExcelConfirmColumnIndexArray(arrayIndexCounter))

        Next

    End With


End Sub

VBA doesn't support initialization of arrays by array literals. VBA不支持通过数组文字初始化数组。 It does, however, have an Array() function: 但它有一个Array()函数:

Dim tradesMasterListColumnIndexArray As Variant
Dim newExcelConfirmColumnIndexArray As variant

tradesMasterListColumnIndexArray = Array(1,4,firmLocationColumn,(firmLocationColumn - 1),(firmLocationColumn + 3),15,16,10,11,8,19,18,17,(firmLocationColumn + 4),9,6,2)
newExcelConfirmColumnIndexArray = Array(1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM