0

I'm a bit new to VBA and don't understand how do I assign specific values into array, not the range. I'm trying to do something like this:

Dim toDel(8) As Integer
Set toDel() = Array(1, 3, 5, 6, 7, 8, 10, 12)

But it returns me error. So can I somehow insert a hole array into array without looping through each element? Like we do it in python just array = array

3
  • 3
    Dim toDel As variant Commented Jul 20, 2021 at 19:44
  • 3
    and toDel = Array(1, 3, 5, 6, 7, 8, 10, 12) Commented Jul 20, 2021 at 19:44
  • 3
    Array() is a function that returns a Variant array, so you can only assign its result to a Variant. If you had a function that returns a strongly typed integer array, you could assign that to an integer array variable, provided it was declared as a dynamic array. You should not use Set. Commented Jul 20, 2021 at 19:58

1 Answer 1

3

Consider:

Option Explicit
Sub whatever()
    Dim toDel As Variant
    toDel = Array(1, 3, 5, 6, 7, 8, 10, 12)
End Sub
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.