Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to split array in excel vba

I had a value in Cells(1,1) as below:

**[[{"Name":Ashwin ,"Age":64}],[],[{"Name":Shakur ,"Age":64,"Gender":Male}]]**

Since it has various i need to print last array element.
My expected output as below
{"Name":Shakur ,"Age":64,"Gender":Male}

Here my code :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

set ws=worksheets("sheet1")
jsontext=worksheets("sheet1").cells(1,1)
set Jsonobject=JsonConverter.ParseJson(jsontext)

for each Item in Jsonobject
 if Item="Gender" then 
 end if
next

Cells(1,1) has the above [[{"Name":Ashwin ,"Age":64}],[],[{"Name":Shakur ,"Age":64,"Gender":Male}]]

When am running the above loop,it was failed due to "[[" in starting.I removed it in cell and run it ,it will considered only {"Name":Ashwin ,"Age":64}.I need to loop until 3rd array…So i tried to split up into array wise and tried to run it in code

>Solution :

Option Explicit
Sub ExampleSplit()
Dim s As String, vx() As String
s = "**[[{""Name"":Ashwin ,""Age"":64}],[],[{""Name"":Shakur ,""Age"":64,""Gender"":Male}]]**"
vx = Split(s, "{")
MsgBox "{" & Split(vx(UBound(vx)), "}")(0) & "}"
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading