+ Reply to Thread
Results 1 to 18 of 18

Compare JSON data and splitting into corrected codes, deleted codes and added codes

Hybrid View

  1. #1
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Compare JSON data and splitting into corrected codes, deleted codes and added codes

    chandramouliarun,

    This is how I interpret the problem and my result is slightly different from yours.
    Sub test()
        Dim a, e, i As Long, ii As Long, dic As Object, m
        Set dic = CreateObject("Scripting.Dictionary")
        a = Sheets("input ").Cells(1).CurrentRegion.Value
        For i = 2 To UBound(a, 1)
            If Not dic.exists(a(i, 1)) Then
                Set dic(a(i, 1)) = CreateObject("Scripting.Dictionary")
                dic(a(i, 1))(a(1, 1)) = a(i, 1)
                dic(a(i, 1))(a(1, 2)) = a(i, 2)
                dic(a(i, 1))("codername") = a(i, 4)
                GetDetails a(i, 3), a(i, 1), dic, True
            Else
                GetDetails a(i, 3), a(i, 1), dic, False
            End If
        Next
        With Sheets("output").Cells(1).CurrentRegion
            .Offset(1).ClearContents
            For i = 0 To dic.Count - 1
                For ii = 1 To .Columns.Count
                    .Cells(i + 2, ii) = dic.items()(i)(.Cells(1, ii).Value)
                Next
            Next
        End With
    End Sub
    
    Private Sub GetDetails(ByVal txt As String, myKey, dic As Object, flg As Boolean)
        Dim m As Object
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = """description"": *""(.+?)"".*[\r\n]+.*""dCode"": *""(.+?)"""
            For Each m In .Execute(txt)
                If flg Then
                    dic(myKey)(m.submatches(0)) = m.submatches(1)
                Else
                    If dic(myKey).exists(m.submatches(0)) Then
                        If dic(myKey)(m.submatches(0)) <> m.submatches(1) Then
                            dic(myKey)("correctedcode") = dic(myKey)("correctedcode") & _
                            IIf(dic(myKey)("correctedcode") <> "", ", ", "") & m.submatches(1)
                            dic(myKey)("deletedcode") = dic(myKey)("deletedcode") & _
                            IIf(dic(myKey)("deletedcode") <> "", ",", "") & dic(myKey)(m.submatches(0))
                            dic(myKey)(m.submatches(0)) = m.submatches(1)
                        End If
                    Else
                        dic(myKey)("addedcode") = m.submatches(1)
                    End If
                End If
            Next
        End With
    End Sub
    Last edited by jindon; 11-30-2020 at 12:58 PM. Reason: One line replaced.

  2. #2
    Forum Contributor
    Join Date
    10-18-2016
    Location
    Chicago, USA
    MS-Off Ver
    Office 365
    Posts
    220

    Re: Compare JSON data and splitting into corrected codes, deleted codes and added codes

    @Jindon: Can you please share your excel sheet with the output...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compare JSON data and splitting into corrected codes, deleted codes and added codes
    By chandramouliarun in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-29-2020, 12:06 PM
  2. Added codes to macro and some codes no longer work
    By alisoncleverly in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2020, 01:26 PM
  3. [SOLVED] Convert Y Codes from one column to another based on Unique Codes
    By ashishmehra2010 in forum Excel General
    Replies: 2
    Last Post: 10-06-2015, 09:49 PM
  4. Replies: 7
    Last Post: 08-13-2015, 10:58 AM
  5. Replies: 1
    Last Post: 12-10-2013, 12:28 AM
  6. Replies: 0
    Last Post: 10-09-2013, 07:59 PM
  7. Combining vba codes makes the previous codes broken !
    By MDPLUS in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-26-2013, 10:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1