Array from Range in Excel VBA

前端 未结 5 763
孤独总比滥情好
孤独总比滥情好 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:30

    The problem is in LBound and UBound

    jtolle was correct about the LBound and UBound.

    LBound(item, 2)
    
    UBound(item, 2)
    

    However, item must not be dimmed as an array (you'll get an error).

    I think this is what you want

    Dim item As Variant
    MsgBox Range("D19:H19").Count
    item = Range("D19:H19").Value
    
    MsgBox LBound(item, 2) & " " & UBound(item, 2)
    
    For i = LBound(item, 2) To UBound(item, 2)
      MsgBox item(1, i)
    Next
    

提交回复
热议问题