Forum Discussion
VBA with Stockhistory
Admins, Hope I followed the community rules here.
CALVIN2021 Hi, I too came here for the answer and went through the other forums but couldn't find the solution. The problem seems that StockHistory function shows #Busy while the VBA code is in process however the data appears once the macro is completed. As I too wanted to have more than 10 stocks historical data from a single macro and found a workaround which worked for me but its not a solution. Maybe someone from the esteemed programmer community can recommend solution. Hope this makes little easier for you too. I split my macro's into two parts -
A. Pull all the data first into multiple tabs as per the stock name and the data will appear as the macro function is completed.
B. Once the first macro completes, you can use your second macro to start the remaining work.
First Macro lines for workaround
Sub PullStockData()
For i = 1 To 6
Sheets("Stocks").Activate ' ---- All the stocks name are listed in this sheet
Stock = Range("A" & i).Value
StartDate = Range("E1").Value
EndDate = Range("E2").Value
Sheets.Add After:=ActiveSheet
ActiveSheet.Name = "S_" & Stock
Range("A1").Select
ActiveCell.Formula2R1C1 = _
"=STOCKHISTORY(""XNSE:"" & """ & Stock & """,""" & StartDate & """,""" & EndDate & """,0,1,0,1,2,3,4,5)"
Next i
End Sub