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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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