How store a range from excel into a Range variable?

后端 未结 5 1477
时光说笑
时光说笑 2021-01-04 12:15

I am reading some cells of excel using VBA.

Function getData(currentWorksheet as Worksheet, dataStartRow as Integer, _
dataEndRow as Integer, DataStartCol as         


        
5条回答
  •  情书的邮戳
    2021-01-04 13:08

    Declare your dim as a variant, and pull the data as you would from an array. i.e.

    Dim y As Variant
    y = Range("A1:B2")
    

    Now your excel range is all 1 variable (array), y

    To pull the data, call the array position in the range "A1:B2" or whatever you choose. e.g.:

    Msgbox y(1, 1)
    

    This will return the top left box in the "A1:B2" range.

提交回复
热议问题