VBA Macro, read range from Sheet2 not working

yousufj56

Board Regular
Joined
May 22, 2014
Messages
51
Hi, I have this code for getting JSON data from a specifc URLs that are listed in Sheet2, column A. However, i keep getting an error on the "If" statement. Anyone know how to resolve this?

Code:
Public Sub NEWURL()
    Dim https As Object, Json As Object, i As Integer, j As Integer


    Dim Item As Variant


    Set https = CreateObject("MSXML2.XMLHTTP")


    For j = 0 To Sheets("Sheet2").UsedRange.Rows.Count
        If Len(Trim$(Sheets("Sheet2").Range("A" & i).Value2)) > 0 Then
            https.Open "GET", Trim$(Sheets("Sheet2").Range("A" & i).Value2), False
            https.Send


            Set Json = JsonConverter.ParseJson(https.responseText)


            i = 2
            For Each Item In Json.Items
                Sheets("Sheet6").Cells(i, 2).Value = Item
                i = i + 1
            Next Item
        End If
    Next j


    MsgBox ("complete")
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
;) It will probably work better if you change i to j:

Code:
For j = 0 To Sheets("Sheet2").UsedRange.Rows.Count
    If Len(Trim$(Sheets("Sheet2").Range("A" & [COLOR=#ff0000][B]i[/B][/COLOR]).Value2)) > 0 Then

.. and also start at j=1 rather than 0.
 
Upvote 0
Thanks, I changed that but it's still giving me the same error... Do you see anything else wrong there?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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