"Semi-dynamic" array

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
How do I make the following code to work? I need an array that has nothing but strings in it and has two dimensions (X rows, 5 columns). The amount of rows changes a lot, it can be one, it can be one thousand.

Code:
Sub arraytest()
    Dim sHaettavat() As String
    Dim lRow As Long

    lRow = 1 'This can be any positive integer
    sHaettavat(lRow, 1) = "0.0.1.0."
    sHaettavat(lRow, 2) = "002F_002A_"
    sHaettavat(lRow, 3) = "002F_"
    sHaettavat(lRow, 4) = "No"
    sHaettavat(lRow, 5) = "Comment"
End Sub
It gives now "Run-time error '9': Subscript out of range error"

The problem is most likely on that "Dim sHaettavat() As String" row, but how do I fix it? "Dim sHaettavat(,5) As String" doesn't work either.

Am I forced to use some kind of variant even if there's nothing but strings?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,

Perhaps this?

Code:
Sub arraytest()
    Dim sHaettavat() As String
    
    Dim lRow As Long
    
    lRow = 1 'This can be any positive integer
    
    ReDim sHaettavat(1 To lRow, 1 To 5) As String
    
    sHaettavat(lRow, 1) = "0.0.1.0."
    sHaettavat(lRow, 2) = "002F_002A_"
    sHaettavat(lRow, 3) = "002F_"
    sHaettavat(lRow, 4) = "No"
    sHaettavat(lRow, 5) = "Comment"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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