VBAmacros对于下一个循环

我是编码的小白。 我得到了帮助创build下面的代码。 但是,我需要创build一个for和下一个循环。 基本上,URL = Sheets(“Sheet2”)。Range(A:A)

URL需要在每个循环中更改。 该URL将从A1中列出,并下降到某个A(X)。

我听说很容易做,但我已经花了几个小时,试图学习它,超出了我的技能…

Sub Test7() 'Haluk '11/12/2017 Dim objHTTP As Object Dim MyScript As Object Dim myData As Variant Dim myLength As Byte 'Clean the sheet ActiveSheet.Cells.Clear URL = "https://min-api.cryptocompare.com/data/histominute?fsym=BTC&tsym=USD&limit=60&aggregate=3&e=CCCAGG" 'The returned JSon table contents have the primary key/label named as "Data" 'We are going to refer this "Data" in the following two JScripts "getValue" and "getLength" Set MyScript = CreateObject("MSScriptControl.ScriptControl") MyScript.Language = "JScript" MyScript.AddCode "function getValue(JSonList, JItem, JSonProperty) { return JSonList.Data[JItem][JSonProperty]; }" MyScript.AddCode "function getLength(JSonList) { return JSonList.Data.length; }" Set objHTTP = CreateObject("MSXML2.XMLHTTP") objHTTP.Open "GET", URL, False objHTTP.Send 'Get the JSon table Set RetVal = MyScript.Eval("(" & objHTTP.responseText & ")") objHTTP.abort 'Retrieve the value of the key "close" in the 4th item of the data set "Data" 'with the help of the JScript function "getValue" above myData = MyScript.Run("getValue", RetVal, 4, "close") MsgBox "This is a small demo...." & vbCrLf & vbCrLf _ & "Value of the key 'close' of the 4th data in the JSON table is: " & myData 'Get the count of items in the JSon table under "Data" myLength = MyScript.Run("getLength", RetVal) 'Write labels of the key in the table to the sheet Range("B1") = "time" Range("C1") = "close" Range("D1") = "high" Range("E1") = "low" Range("F1") = "open" Range("G1") = "volumefrom" Range("H1") = "volumeto" Range("J1") = "TimeFrom:" Range("J2") = "TimeTo:" Range("B1:H1, J1:J2").Font.Bold = True Range("B1:H1, J1:J2").Font.Color = vbRed 'Get all the values of the JSon table under "Data" For i = 0 To myLength - 1 Range("A" & i + 2) = "Data -" & i Range("B" & i + 2) = MyScript.Run("getValue", RetVal, i, "time") / (CDbl(60) * CDbl(60) * CDbl(24)) + #1/1/1970# Range("C" & i + 2) = MyScript.Run("getValue", RetVal, i, "close") Range("D" & i + 2) = MyScript.Run("getValue", RetVal, i, "high") Range("E" & i + 2) = MyScript.Run("getValue", RetVal, i, "low") Range("F" & i + 2) = MyScript.Run("getValue", RetVal, i, "open") Range("G" & i + 2) = MyScript.Run("getValue", RetVal, i, "volumefrom") Range("H" & i + 2) = MyScript.Run("getValue", RetVal, i, "volumeto") Next 'Get the time info given in the JSon table Range("K1") = RetVal.TimeFrom / (CDbl(60) * CDbl(60) * CDbl(24)) + #1/1/1970# Range("K2") = RetVal.TimeTo / (CDbl(60) * CDbl(60) * CDbl(24)) + #1/1/1970# Set objHTTP = Nothing Set MyScript = Nothing End Sub 

把这些线以外的东西放在一个循环中

 Dim objHTTP As Object Dim MyScript As Object Dim myData As Variant Dim myLength As Byte 'Clean the sheet ActiveSheet.Cells.Clear 

for x = 1 to Application.Counta(Sheet2.Columns(1))
剩下的代码
下一个

将URL行更改为URL=Sheet2.Cells(x,1)

和范围Sheet1.Range