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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:18+00:00 2026-05-13T05:30:18+00:00

What is the proper way to handle a module level array in a VBA

  • 0

What is the proper way to handle a module level array in a VBA class?

I use Property Let and Property Get for other variables, but I haven’t figured out how to pass arrays to and from Properties.

Updated. This code works thanks to Mark Nold.

Option Explicit

Private mstrTestArray() As String

Public Property Get TestArray() As String()
    TestArray = mstrTestArray
End Property
Public Property Let TestArray(ByRef strTestArray() As String)
    mstrTestArray = strTestArray
End Property
Public Property Get TestArrayValue(d1 As Long, d2 As Long) As String
    TestArrayValue = mstrTestArray(d1, d2)
End Property
Public Property Let TestArrayValue(d1 As Long, d2 As Long, strValue As String)
    strTestArray(d1, d2) = strValue
End Property

Sub DoTest()

    Dim strTestArray() As String
    ReDim strTestArray(2, 1) As String

    strTestArray(0, 0) = "a": strTestArray(0, 1) = "one"
    strTestArray(1, 0) = "b": strTestArray(1, 1) = "two"
    strTestArray(2, 0) = "c": strTestArray(2, 1) = "three"

    TestArray = strTestArray

    Debug.Print TestArrayValue(UBound(TestArray, 1), UBound(TestArray, 2))

End Sub

The following does not work. This top part is a method in the above class:

Sub LetArrayFromReference(ByRef strTestArray() As String)
    TestArray = strTestArray
End Sub

This part is a procedure that calls the class:

Sub DoTest()

    Dim strTestArray() As String
    ReDim strTestArray(2, 1) As String
    Dim objTestClass As New TestClass

    strTestArray(0, 0) = "a": strTestArray(0, 1) = "one"
    strTestArray(1, 0) = "b": strTestArray(1, 1) = "two"
    strTestArray(2, 0) = "c": strTestArray(2, 1) = "three"

    objTestClass.LetArrayFromReference strTestArray

    Debug.Print objTestClass.TestArrayValue(UBound(objTestClass.TestArray, 1) _
    , UBound(objTestClass.TestArray, 2))

End Sub

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-13T05:30:19+00:00Added an answer on May 13, 2026 at 5:30 am

    The code below might give you some clues to help. First define a class called TestClass.

    Option Explicit
    
    Private strTestArray() As String
    
    Public Property Get TestArrayValue(d1 As Long, d2 As Long) As String
        TestArrayValue = strTestArray(d1, d2)
    End Property
    
    Public Property Let TestArrayValue(d1 As Long, d2 As Long, sValue As String)
        strTestArray(d1, d2) = sValue
    End Property
    
    
    Sub DoTest()
    
        Dim myTestArray() As String
        ReDim myTestArray(3, 1) As String
    
        myTestArray(0, 0) = "a": myTestArray(0, 1) = "one"
        myTestArray(1, 0) = "b": myTestArray(1, 1) = "two"
        myTestArray(2, 0) = "c": myTestArray(2, 1) = "three"
    
        strTestArray = myTestArray
        Me.TestArrayValue(3, 1) = "Hello"
    
    
        Debug.Print strTestArray(2, 1)
        Debug.Print Me.TestArrayValue(1, 1)
        Debug.Print Me.TestArrayValue(3, 1)
    
    End Sub
    

    Then in a code module or a worksheet create a sub called MyTest();

    Option Explicit
    
    Sub MyTest()
      Dim t As New TestClass
      t.DoTest  
    
      Debug.Print "The value at 1,1 is; " & t.TestArrayValue(1, 1)
    End Sub
    

    Within the class you can update strTestArray() or Me.TestArrayValue. I’ll let you create a Get and set for TestArray. I’m not 100% sure of what you are trying to do..so if you have any questions leave a comment and update your OP 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 422k
  • Answers 422k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here are some solutions that works. http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/ http://urlrewriter.net/ http://www.codeproject.com/KB/aspnet/urlrewriter.aspx Select… May 15, 2026 at 11:10 am
  • Editorial Team
    Editorial Team added an answer Whenever you pass a string of HTML to any of… May 15, 2026 at 11:10 am
  • Editorial Team
    Editorial Team added an answer I fixed this problem through a mathematical rearrangement rather than… May 15, 2026 at 11:10 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.