Array from Range in Excel VBA

前端 未结 5 766
孤独总比滥情好
孤独总比滥情好 2020-12-18 02:07

Well I\'ve been struggling with the little bit of code and can\'t seem to get around it ... I\'m trying to get an array from a range of cells, the array however is showing u

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 02:32

    Your item should contain a 2-D array as expected. If you stick a breakpoint in your code and look at the little "Locals" window in the VBA editor, you should see that. Your calls to LBound and UBound are getting the bounds in the first dimension. If you call Lbound(item,2) and UBound(item,2), you should get 1 and 5 as you expect.

    EDIT: That is, once you've made the assignment, item would look like something you could have declared as such:

    Dim item(1 to 1, 1 to 5)

    One of the banes of VBA programming is that arrays can have arbitrary lower bounds. So all of your code needs to be aware of that.

提交回复
热议问题