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 7966491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:26:30+00:00 2026-06-04T06:26:30+00:00

This is a matter of personal curiosity. In VBA, if I have an array

  • 0

This is a matter of personal curiosity.

In VBA, if I have an array of size 2:

Dim r(1) as Variant

And I want both values in the array to be -1. I can do this:

r(0)=-1
r(1)=-1

Or I could iterate through both with a loop and set them to -1.

So my question is, is there any way I can set all the values in an array to the same thing without iterating?

Or, is there any way I can do something like:

r = array(-1,-1)

This might be a really stupid question but I can’t seem to find the answer.

  • 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-04T06:26:32+00:00Added an answer on June 4, 2026 at 6:26 am

    Yes you can do it. But then you have to take care while declaring the array

    Example

    Option Explicit
    
    Sub Sample()
        Dim r As Variant '<~~
    
        r = Array(-1, -1)
    
        Debug.Print r(0)
        Debug.Print r(1)
    End Sub
    

    FOLLOWUP

    See the Excel Help File 🙂 The Array Function returns a Variant containing an array. You cannot assign an array to another array directly. To assign an array to another array you have to use this method.

    Option Explicit
    
    Sub Sample()
        Dim r(1) As Variant 
        Dim s As Variant
        Dim i As Long
    
        s = Array(-1, -1)
    
        For i = LBound(r) To UBound(r)
           r(i) = s(i)
        Next
    
        Debug.Print r(0)
        Debug.Print r(1)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python program (with Django - does this matter?) that I want
This is probably a matter of personal preference, but when do you use properties
This should be totally simple but I can't get it working no matter what
I can't figure this one out no matter how many times I google it
I currently have an array I created like this: $regions=array( 1=>'North West', 2=>'North East',
Possible Duplicate: How can I parse this JSON in Android? I have a requirement,
I had a question regarding this matter some days ago, but I'm still wondering
I'm totally confused on this matter, some say use tables and others say it's
This may be a matter of taste but when creating ViewModels is it best
This is probably a simple matter, but when I create a new object, the

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.