Populating dynamic array


I have a small VBA subroutine, which aims to put some data from a worksheet into a two dimensional dynamic array. When compiled line-by-line (“step into”), it seems to work sometimes, that is, the data from the worksheet indeed gets into the array. However, when running by “Run Sub”, I get “Application-defined or object-defined error.” After such an error, even after stopping, and re-starting by “step into” leads to the same error again. (Nothing is changed on worksheet in the meanwhile.) Why is this happening? If my code is wrong, how come it works sometimes?


Sub CountYESArray()

Dim DataArray() As Variant, dataRows As Long, dataCols As Long

dataRows = Worksheets(“DS”).UsedRange.Rows.Count – 1
dataCols = Worksheets(“DS”).UsedRange.Columns.Count

ReDim DataArray(dataRows, dataCols)
DataArray = Worksheets(“DS”).Range(“A2”, Range(“c1”).End(xlDown)).Value

End Sub



By: Kinga

14 thoughts on “Populating dynamic array

  1. ig

    You actually make it appear so easy together with your presentation however I find this matter to be actually something
    that I think I might never understand. It seems
    too complicated and extremely wide for me.
    I am taking a look ahead in your next post, I’ll attempt to get the cling of it!

  2. Emory

    Hi, I do think this is an excellent website. I stumbledupon it ;
    ) I will come back once again since i have
    book-marked it. Money and freedom is the best way to change, may you
    be rich and continue to guide others.

  3. sling tv

    Hey there, You have done an excellent job. I’ll definitely digg it
    and personally suggest to my friends. I’m sure they will be
    benefited from this website.

  4. match.com free trial

    You can definitely see your expertise in the work you
    write. The arena hopes for more passionate writers
    like you who are not afraid to mention how they believe. All the time follow your heart.

  5. coconut oil

    Wow that was odd. I just wrote an extremely
    long comment but after I clicked submit my comment didn’t
    appear. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say
    wonderful blog!

  6. quest bars cheap coupon twitter

    It’s perfect time to make some plans for the future and it’s time to
    be happy. I have read this publish and if I may just I desire
    to suggest you few interesting issues or suggestions.

    Maybe you could write subsequent articles regarding this article.
    I want to read more things about it!

  7. quest bars cheap

    Hi there! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no back up.

    Do you have any methods to protect against hackers?

Comments are closed.