简体   繁体   中英

Type mismatch error when creating a vba array

I'm trying to drop a range of cells straight into an array to run some calculations. The range will always be A8:E?, but I never know how many total rows there will be. One of the columns contains string values that I need for determining conditions. I set a variable to find the last row (and no, this data never has any blanks so the method to set it works just fine). This is what I have"

    Sub use_arr()
    Dim rw As Integer

    rw = Worksheets("Sheet1").Range("A8").End(xlDown).Row

    Dim myArr()

    myArr = Worksheets("Sheet1").Range("A8:E" & rw)

    End Sub

But it keeps throwing a "Run_time error '13'" at me.

Arrays are still new to me, someone suggested using them instead of looping through cells for faster execution. So I'm still figuring this out.

要么将myArr声明为Variant ,而不是数组,要么指定范围的Value属性:

myArr = Worksheets("Sheet1").Range("A8:E" & rw).Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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