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

  • SEARCH
  • Home
  • 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 8465387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:01:46+00:00 2026-06-10T15:01:46+00:00

This is an awesomely simple problem, but I’ve been breaking my head against it

  • 0

This is an awesomely simple problem, but I’ve been breaking my head against it for an hour. I’m trying to do the following:

  1. define a VBA array from a named range in my spreadsheet
  2. Access an item in that array

Now, if the named range happens to cover a multi-dimensional area (rows and columns), then this works fine:

foobar = Range("two_dimensional_range")
MsgBox foobar(1,1)

However, if the named range consists of a single dimension (just a column) of data, then this produces a “Subscript Out of Range” error:

foobar = Range("one_dimensional_range")
MsgBox foobar(1)

I’ve verified that foobar is really an array. I can iterate through it with For Each … Next. If I call Ubound(foobar) then it gives me the correct size. I just can’t access a single element of it directly!

What am I doing wrong?

  • 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-06-10T15:01:48+00:00Added an answer on June 10, 2026 at 3:01 pm

    When you assign a range (Not a single cell) to a variant array, It will always be a multidimensional array so this MsgBox foobar(1,1) will still work in the 2nd instance.

    See this example

    Option Explicit
    
    Sub Sample()
        Dim Ar As Variant
    
        Ar = Range("A1:A2")
    
        Debug.Print Ar(1, 1)
        Debug.Print Ar(2, 1)
    End Sub
    

    Another example

    Option Explicit
    
    Sub Sample()
        Dim Ar As Variant
    
        Ar = Range("A1:B2")
    
        '~~> Get Values from Col A
        Debug.Print Ar(1, 1)
        Debug.Print Ar(2, 1)
    
        '~~> Get Values from Col B
        Debug.Print Ar(1, 2)
        Debug.Print Ar(2, 2)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a simple problem. But im totally stuck with this error. I
So I'm having this problem, it should be pretty simple, but I don't know
Hey There, This is a pretty simple problem, but it is my first time
Im trying to debug where the problem is in this dynamic input generator tool
I've been trying to get this javascript animation to work for hours now, and
I have been trying to upload a .txt to my server via a simple
This may be a really simple question, but I'm not sure what the most
I am trying to get this awesome JQuery plugin working with SQL Server. I
this is my first time posting on StackOverflow but this site is awesome. Thanks
I'm hoping to get some help with this weird problem. We're running the Jacorb

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.