Basic syntax for loading a 2 dimensional array

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
Array specialists

I apologize for asking a question that has probably been asked a million times but I've forgotten how to use a 2d array. I tried looking at stuff on the internet but cannot quite get it right. Hopefully pseudocode below shows what I'm trying to do. For my attempt to redim excel tells me that the array is already dimensioned. I'd really appreciate your assistance.

VBA Code:
Option Base 1

Sub LoadArray()

    Dim asPeople(6, 1) As String
    
    asPeople(1, 1) = "First Name"
    asPeople(2, 1) = "Last Name"
    asPeople(3, 1) = "Email"
    asPeople(4, 1) = "Phone"
    asPeople(5, 1) = "Shift"
    asPeople(6, 1) = "Notes"
    
    ReDim Preserve asPeople(6, 2)
    
    asPeople(1, 2) = "Bill"
    asPeople(2, 2) = "Ding"
    asPeople(3, 2) = "bill@email.com"
    asPeople(4, 2) = "555 234 5678"
    asPeople(5, 2) = "First"
    asPeople(6, 2) = "Good experience"

    ReDim Preserve asPeople(6, 3)

    asPeople(1, 3) = "Bill"
    asPeople(2, 3) = "Dupp"
    asPeople(3, 3) = "bdupp@email.com"
    asPeople(4, 3) = "444 234 5678"
    asPeople(5, 3) = "Second"
    asPeople(6, 3) = "No experience"

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
OK, so I fiddled a bit more and I think I have it. The initial dim does not have any indexing specified, so my initial dim should be Dim asPeople() As String
 
Upvote 0
Solution

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top