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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:35:23+00:00 2026-05-29T09:35:23+00:00

I have a VBA Sub that create and handle an array: Option Base 1

  • 0

I have a VBA Sub that create and handle an array:

Option Base 1
Public myArr(20, 10) As Variant

Sub Stackoverflow()
Dim x, y As Integer
    'Put some values to array (only in the first 15 rows)
    For x = 1 To 15
        For y = 1 To 10
            myArr(x, y) = (x * y + 8)
        Next y
    Next x
End Sub

Then there is a userform with a commandbutton that should be able to handle the array myArr.

Private Sub commandbutton_Click()
Dim a, b As Integer
    'Put some other values in the remaining rows
    For a = 16 To 20
        For b = 1 To 10
            myArr(a, b) = (a * b + 3)
        Next b
    Next a
End Sub

How can I pass the array to the userform? And how the Sub can view the updated array?
Thanks

  • 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-29T09:35:24+00:00Added an answer on May 29, 2026 at 9:35 am

    Your code worked perfectly for me once I had completed it. I can only assume you do not know how to call the userform.

    I copied your Stackoverflow() to a module without changes.

    To the same module I added:

    Sub Main()
    
      Dim RowMyArr As Long
      Dim ColMyArr As Long
    
      Load UserForm1
    
      Call Stackoverflow
    
      UserForm1.Show
    
      Debug.Print "    ";
      For ColMyArr = LBound(myArr, 1) To UBound(myArr, 1)
        Debug.Print Right("   " & ColMyArr, 4) & " ";
      Next
      Debug.Print
    
      For RowMyArr = LBound(myArr, 2) To UBound(myArr, 2)
        Debug.Print Right("  " & RowMyArr, 3) & " ";
        For ColMyArr = LBound(myArr, 1) To UBound(myArr, 1)
          Debug.Print Right("   " & myArr(ColMyArr, RowMyArr), 4) & " ";
        Next
        Debug.Print
      Next
    
    End Sub
    

    I created a user form and did not change the default name from UserForm1. I added a button, named it commandbutton and copied your code to the form’s code area. Before the End Sub, I added Unload UserForm1 to close and exit the form.

    I ran Main and the following was output to the immediate window:

           1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20 
      1    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   19   20   21   22   23 
      2   10   12   14   16   18   20   22   24   26   28   30   32   34   36   38   35   37   39   41   43 
      3   11   14   17   20   23   26   29   32   35   38   41   44   47   50   53   51   54   57   60   63 
      4   12   16   20   24   28   32   36   40   44   48   52   56   60   64   68   67   71   75   79   83 
      5   13   18   23   28   33   38   43   48   53   58   63   68   73   78   83   83   88   93   98  103 
      6   14   20   26   32   38   44   50   56   62   68   74   80   86   92   98   99  105  111  117  123 
      7   15   22   29   36   43   50   57   64   71   78   85   92   99  106  113  115  122  129  136  143 
      8   16   24   32   40   48   56   64   72   80   88   96  104  112  120  128  131  139  147  155  163 
      9   17   26   35   44   53   62   71   80   89   98  107  116  125  134  143  147  156  165  174  183 
     10   18   28   38   48   58   68   78   88   98  108  118  128  138  148  158  163  173  183  193  203 
    

    I have not checked the values but I assume they are correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very simple problem: I have a Public Sub (in a module) that I want
In Excel VBA (2003), I've noticed that any Public or Friend Sub method in
I have an Excel VBA sub that (among other things) pastes a lookup formula
I have the following VBA code Private Sub CreateQuery_Click() Dim doc As Document Dim
I have currently written a sub, written in VBA, that is called by the
Does VBA have dictionary structure? Like key<>value array?
I have a VBA Word Macro that gets words from .txt list and color
I have a VBA script that inserts long strings into Excel cells. In some
I have some VBA code that needs to talk to a running c# application.
Using VBA i have a set of functions that return an ADODB.Recordset where all

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.