Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1054447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:24:29+00:00 2026-05-16T17:24:29+00:00

Does VBA support using an array of range variables? dim rangeArray() as range dim

  • 0

Does VBA support using an array of range variables?

dim rangeArray() as range
dim count as integer
dim i as integer

count = 3

redim rangeArray(1 to count)

for i = 1 to count
  msgbox rangeArray(i).cells(1,1).value
next

I can’t get it to work in this type of application. I want to store a series of ranges in a certain order as a “master copy”. I can then add, delete, sort or do whatever to this array and then just print it out to a series of ranges in excel. It doesn’t seem like excel supports this – it just forces you to store your data in the spreadsheet and you have to reread it in order to use it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:24:30+00:00Added an answer on May 16, 2026 at 5:24 pm

    No, arrays can’t hold objects. But oObjects can hold objects. I think what you may want is a Range object that consists of various specific other Range object. In this example, rMaster is my “array” that holds three cells.

    Sub StoreRanges()
    
        Dim rMaster As Range
        Dim rCell As Range
    
        Set rMaster = Sheet1.Range("A1")
        Set rMaster = Union(rMaster, Sheet1.Range("A10"))
        Set rMaster = Union(rMaster, Sheet1.Range("A20"))
    
        For Each rCell In rMaster
            MsgBox rCell.Address
        Next rCell
    
    End Sub
    

    With my new found knowledge that arrays can hold ranges (thnx jtolle), here’s an example of how you would store ranges in an array and sort them

    Sub UseArray()
    
        Dim aRng(1 To 3) As Range
        Dim i As Long
    
        Set aRng(1) = Range("a1")
        Set aRng(2) = Range("a10")
        Set aRng(3) = Range("a20")
    
        BubbleSortRangeArray aRng
    
        For i = LBound(aRng) To UBound(aRng)
            Debug.Print aRng(i).Address, aRng(i).Value
        Next i
    
    End Sub
    
    Sub BubbleSortRangeArray(ByRef vArr As Variant)
    
        Dim i As Long, j As Long
        Dim vTemp As Variant
    
        For i = LBound(vArr) To UBound(vArr) - 1
            For j = i To UBound(vArr)
                If vArr(i).Value > vArr(j).Value Then
                    Set vTemp = vArr(i)
                    Set vArr(i) = vArr(j)
                    Set vArr(j) = vTemp
                End If
            Next j
        Next i
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does VBA have dictionary structure? Like key<>value array?
I basically want to open a browser window from Word using VBA that does
Does anyone know how to clear the immediate window using VBA? While I can
Does (Excel) VBA distinguish between: Dim Ghadafi as Variant and Dim Ghadafi() as Variant
Does anyone know how to do that? My skills in using VBA aren't very
Does anyone have a good VBA way (or perhaps there is an MS Word
What is a Recordset in VBA? What purpose does it serve? How do you
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
I am using a COM visible C# library that I call from VBA in
I have a simple recursive function to write in VBA that does the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.