i have created this excel sheet to help me out with stock analysis. the main macro within the sheet scrubs yahoo finance and market watch for specific information, throws it into different sheets, copies and pastes it into a summary sheet and then moves on to the next ticker. The macro only works up until 5 tickers. I dont know if it is because my code is not optimized as much as it should be or if there is something else that i can do to allow me to run more than 5 tickers at a time. Any advice would help :)
thank you and i appreciate your time
here is my code for the macro
Sub fundamentals()
'This checks the tickers that we enter at the top of the sheet
Call TurnOffStuff
For i = 2 To Sheets(1).Cells(1, 1).End(xlToRight).column
'This will assign one of the tickers to the variable to be inserted into the url
ticker = Sheets(1).Cells(1, i)
qurl = "https://finance.yahoo.com/quote/" & ticker & "/?p=" & ticker & ""
'This gets the data from yahoofinance's summary page and puts it in sheet 5
Sheets(5).Select
Sheets(5).Cells.Clear
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets(5).range("A2"))
.BackgroundQuery = True
.Refresh BackgroundQuery:=False
End With
'This takes the data that we got off of the url above and copy & paste it to
'main sheet we want our data to be in
Sheets(5).range("B2:B18").Copy
Sheets(1).Select
Cells(2, i).Select
ActiveSheet.Paste
CutCopyMode = False
qurl = "https://finance.yahoo.com/quote/" & ticker & "/key-statistics?p=" & ticker & ""
'This gets the data from yahoofinance's key statistics page and puts it in sheet 2
Sheets(2).Select
Sheets(2).Cells.Clear
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets(2).range("A2"))
.BackgroundQuery = True
.Refresh BackgroundQuery:=False
End With
'This takes the data that we got off of the url above and copy & paste it to
'main sheet we want our data to be in
Sheets(2).range("B20:B78").Copy
Sheets(1).Select
Cells(22, i).Select
ActiveSheet.Paste
CutCopyMode = False
qurl = "https://finance.yahoo.com/quote/" & ticker & "/analysis?p=" & ticker & ""
'This gets the data from yahoofinance's analysis page and puts it in sheet 3
Sheets(3).Select
Sheets(3).Cells.Clear
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets(3).range("A2"))
.BackgroundQuery = True
.Refresh BackgroundQuery:=False
End With
'This takes the data that we got off of the url above and copy & paste it to
'main sheet we want our data to be in
Sheets(3).range("B20:B60").Copy
Sheets(1).Select
Cells(94, i).Select
ActiveSheet.Paste
CutCopyMode = False
Sheets(3).range("C20:C60").Copy
Sheets(1).Select
Cells(136, i).Select
ActiveSheet.Paste
CutCopyMode = False
Sheets(3).range("D20:D60").Copy
Sheets(1).Select
Cells(178, i).Select
ActiveSheet.Paste
CutCopyMode = False
Sheets(3).range("E20:E60").Copy
Sheets(1).Select
Cells(220, i).Select
ActiveSheet.Paste
CutCopyMode = False
qurl = "https://www.marketwatch.com/investing/stock/" & ticker & "/analystestimates?mod=mw_quote_tab"
'This gets the data from market watches anaylst estimate page and puts it in sheet 4
Sheets(4).Select
Sheets(4).Cells.Clear
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Sheets(4).range("A2"))
.BackgroundQuery = True
.Refresh BackgroundQuery:=False
End With
'This takes the data that we got off of the url above and copy & paste it to
'main sheet we want our data to be in
Sheets(4).range("B17:B79").Copy
Sheets(1).Select
Cells(264, i).Select
ActiveSheet.Paste
CutCopyMode = False
Sheets(4).range("C35:C63").Copy
Sheets(1).Select
Cells(327, i).Select
ActiveSheet.Paste
CutCopyMode = False
Sheets(4).range("D35:D63").Copy
Sheets(1).Select
Cells(356, i).Select
ActiveSheet.Paste
CutCopyMode = False
Sheets(4).range("E35:E43").Copy
Sheets(1).Select
Cells(385, i).Select
ActiveSheet.Paste
CutCopyMode = False
Next i
Call TurnOnStuff
Sheets("All Ticker Analysis").Activate
ActiveSheet.Cells(1, 1).Select
End Sub
Sub TurnOffStuff()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
End Sub
Sub TurnOnStuff()
Application.Calculation = xlCalcualtionAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub