1

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.

2
  • If your data is large, I think the type of rw should be long. Commented Nov 6, 2020 at 15:15
  • 1
    Value is required when declaring a dynamic array, and value is not required when it is a static array. That is, if you declare dim myArr, it becomes a static array. Commented Nov 6, 2020 at 15:22

1 Answer 1

3

Either declare myArr just as a Variant, not an array, or specify the Value property of the range:

myArr = Worksheets("Sheet1").Range("A8:E" & rw).Value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.