excel vba how to copy the value of multiple non-contiguous ranges into an array

前端 未结 3 2018
余生分开走
余生分开走 2020-12-03 15:56

I am trying to copy the value of multiple non-contiguous ranges into an array. I wrote code like this:

summaryTempArray = .range(\"A2:D9,A11:D12,A14:D15\").V         


        
3条回答
  •  眼角桃花
    2020-12-03 16:24

    I had the same problem & tried a few methods without success until I hit on this:-

        dim i as integer
        Dim rng1 as range
        Dim str as string
        dim cels() as string
        Set rng1 = sheet1.Range("A2:D9,A11:D12,A14:D15")
        str = rng1.address(0,0)
        cels() = split(str, ",")     '<--- seems to work OK
        for i = 0 to 2
            Debug.Print cels(i)
        Next i             
    

    I would be interested if this is an "incorrect" conversion method.

提交回复
热议问题