Skip to content

Better version that reads the object properties and makes into a table with headers: #495

@orooro

Description

@orooro
          Better version that reads the object properties and makes into a table with headers:
Option Explicit

Public Sub IterateOverACollection()

    Dim jsonString As String
    jsonString = "[{""row"":1, ""a"":""0007"", ""b"":""Blue"", ""c"":""2008""}, {""row"":2, ""a"":null, ""b"":"""", ""c"":""1709""}]"
    
    Dim myCollection As Collection
    Set myCollection = ParseJson(jsonString)
    
    Dim myDictionary As Dictionary
    Dim i As Long, j As Long
    
    Dim StartCell As Range
    Set StartCell = ActiveSheet.Range("A1")
    
    Set myDictionary = myCollection(1)
    For j = 1 To myDictionary.Count
        StartCell.Offset(0, j - 1) = myDictionary.Keys(j - 1)
        StartCell.Offset(0, j - 1).Font.Bold = True
    Next j
    
    For i = 1 To myCollection.Count
        Set myDictionary = myCollection(i)
        For j = 1 To myDictionary.Count
           StartCell.Offset(i, j - 1) = myDictionary.Items(j - 1)
        Next j
    Next i
    
End Sub

screen shot 2018-03-23 at 4 29 41 pm

Originally posted by @zgrose in #329 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions