Iterating through String Array Inside of For Each Loop

stusic

Board Regular
Joined
Dec 15, 2007
Messages
65
Office Version
  1. 365
Platform
  1. Windows
What I'm doing here is parsing a JSON file into a worksheet. The JsonConverter example shows it looking through a defined list of "values":

Code:
' Prepare and write values to sheetDim Values As Variant
ReDim Values(Parsed("values").Count, 3)


Dim Value As Dictionary
Dim i As Long


i = 0
For Each Value In Parsed("values")
  Values(i, 0) = Value([COLOR=#ff0000]"a"[/COLOR])
  Values(i, 1) = Value([COLOR=#ff0000]"b"[/COLOR])
  Values(i, 2) = Value([COLOR=#ff0000]"c"[/COLOR])
  i = i + 1

Next Value


I've created a string array that holds each of the values I need (DirArray) instead of separate "a", "b", "c", and I've got a count of how many items there are (c), but I'm not sure how to loop through each of these inside the For Each statement. I've gotten this far, but I know it's wrong:

Code:
n = 1
i = 0
Do While n <= c
ArrItem = (DirArray(1, n))
For Each Value In Parsed(parent)
  Values(i, 0) = Value(ArrItem)
  i = i + 1
Next Value
n = n + 1
Loop

Any help would be super.
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Figured it out:

Code:
n = 1i = 0
ColLtr = ConvertToLetter(n)
For Each Value In Parsed(parent)
        For n = 1 To c
            ArrItem = (DirArray(1, n))
            Values(i, n - 1) = Value(ArrItem)
        Next n
    i = i + 1
Next Value
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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