EXCEL VBA, For Loop, print loop number?

yousufj56

Board Regular
Joined
May 22, 2014
Messages
51
In my worksheet, i have two sheets. Sheet2 has a list of URLs of JSON files which i will use to extract data from. Sheet1 will be where the JSON data will be extracted to.

I'm using a loop like below to extract the data sets. However, the data sets all vary in size so i need to know which loop number each set belongs to. Knowing the loop number will allow me to figure out which URL it belongs too.

Is there a way i can do that? Or is there a way maybe i can just print the URL from Sheet2 to the appropriate set?

Hope that makes sense...

Code:
For x = 1 To Application.CountA(Sheet2.Columns(1))
        URL = Sheets(2).Cells(x, 1)
        objHTTP.Open "GET", URL, False
        objHTTP.Send

If objHTTP.ReadyState = 4 Then
            If objHTTP.Status = 200 Then
            
                Set RetVal = MyScript.Eval("(" & objHTTP.responseText & ")")
                objHTTP.abort
                
                Set MyList1 = RetVal.result.buy
                NoA = Sheet1.Cells(65536, 1).End(xlUp).Row + 1
                
                For Each myData In MyList1
                    Sheets(1).Cells(NoA, 1).Value = myData.Quantity
                    Sheets(1).Cells(NoA, 2).Value = myData.Rate
                    NoA = NoA + 1
                Next
Next
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
i need to know which loop number each set belongs to. Knowing the loop number will allow me to figure out which URL it belongs too.
Since "x" is your loop number, just use that. You can place it on your sheet somewhere if you want.
It really depends on what you need to do with it.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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