ranjithkumar10

Excel to custom json

Sep 30th, 2016
1,811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.62 KB | None | 0 0
  1. Public Sub exceltocustomjson()
  2. Dim rng As Range, items As New Collection, myitem As New Dictionary, i As Integer, cell As Variant, mainContainer As New Dictionary
  3. Set rng = Range("A2:A3")
  4. 'Set rng = Range(Sheets(2).Range("A2"), Sheets(2).Range("A2").End(xlDown)) use this for dynamic range
  5. i = 0
  6. For Each cell In rng
  7. Debug.Print (cell.Value)
  8. myitem("name") = cell.Value
  9. myitem("email") = cell.Offset(0, 1).Value
  10. myitem("phone") = cell.Offset(0, 2).Value
  11. items.Add myitem
  12. Set myitem = Nothing
  13. i = i + 1
  14. Next
  15. mainContainer.Add "price", items
  16. Sheets(2).Range("A4").Value = ConvertToJson(mainContainer, Whitespace:=2)
  17. End Sub
Add Comment
Please, Sign In to add comment