1

I have looked at just about every post I could find on this topic, but I can't seem to get anything to work.

I want to be able to use a 2D Array for my own sake, but I think my best bet is to just make one huge 1D Array.

Sub GatherData()
Dim width As Integer: width = 22

Dim data() As Variant
ReDim roadway(width) As Variant

Dim str As Variant
Dim arrayWidth As Integer

With ThisWorkbook.Worksheets("List of Roads").Range("A1")

    For r = 0 To 400 '400 is an arbitrary number
        If Not IsEmpty(.Offset(r, 0).value) Then
            If IsStreet(UCase(.Offset(r, 0).value), UCase(.Offset(r, 1).value)) Then
                For c = 0 To width - 1
                    roadway(c) = .Offset(r, c).value
                Next c
            End If

            'add roadway array to the end of data()

        End If
    Next r
End With

End Sub

If I had my way this 2D-Array would have an unknown number of rows with each row containing 22 columns. I just can't wrap my head around how I would dynamically add arrays together.

3
  • 1
    Do you need a 1D or 2D array in the end? Had to ask since I cannot see a question in.. question. Commented Feb 19, 2018 at 6:43
  • I don't need a 2D array. Just wanted one. It would make my code look a little cleaner in the end. Plus this would be my first time working with a multi-dim array. Commented Feb 19, 2018 at 18:21
  • @khorn06, may be you could add some examples about wanted array result Commented Feb 19, 2018 at 21:55

1 Answer 1

1
Dim data
data = ThisWorkbook.Worksheets("List of Roads").Range("A1").Resize(400, 22).Value

would give you a 2D array (1 to 400, 1 to 22)

Sign up to request clarification or add additional context in comments.

2 Comments

The 400 is just an arbitrary number.. the actual size the of 2d array I would need for this specific case is 118 rows. In the future that number will change.
So what exactly will determine the size of the array (# of "rows")?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.