I have VBA code that gets the stock price in a loop.
There are stock symbols not found in this API source. It will result to error for those stocks.
I'm using On Error Resume Next
so the VBA code will continue to the next symbol.
My problem is the symbol in error will return a stock price of the last stock symbol not in error.
I would like to make the result blank or zero for the stock symbols in error.
Current Result - the italicized symbols are those that are in error.
Stock Symbol Price
BDO 158.00
ABS 15.80
GREEN 1.87
ALHI 1.87
LAND 1.87
PLC 0.57
LBC 0.57
EVER 0.57
Desired Result - the italicized symbols those that are in error will result or will give return of 0
Stock Symbol Price
BDO 158.00
ABS 15.80
GREEN 1.87
ALHI 0
LAND 0
PLC 0.57
LBC 0
EVER 0
Set myrequest = CreateObject("WinHttp.WinHttpRequest.5.1")
myrequest.Open "Get", "http://phisix-api.appspot.com/stocks/" & symbol & ".json"
myrequest.Send
Dim Json As Object
Set Json = JsonConverter.ParseJson(myrequest.ResponseText)
i = Json("stock")(1)("price")("amount")
ws.Range(Cells(n, 2), Cells(n, 2)) = i
n = n + 1
On Error Resume Next
Next X
ws.Columns("B").AutoFit
MsgBox ("Stock Quotes Refreshed.")
ws.Range("B4:B" & lastrow).HorizontalAlignment = xlGeneral
ws.Range("B4:B" & lastrow).NumberFormat = "#,##0.00"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub