captainxcel
New Member
- Joined
- Jul 28, 2017
- Messages
- 35
- Office Version
- 2016
- Platform
- Windows
Hi everyone: I've been running a macro which pulls in historical stock price data for a series of tickers (range names of tick1, tick2, tick3, etc.). I've yet to combine the 'fetcher' workbook into the destination workbook, but no matter. What I'd really like to do is condense the code into a loop so that I can make the code more efficient. Right now I have the code set up sequentially with a procedure for each ticker as below. Anything else you see as well to make the code more efficient. Thanks in advance!
' Ticker 1 Procedure
Windows("HistData.xlsm").Activate
Application.Goto Reference:="tick1"
Application.CutCopyMode = False
Selection.Copy
Windows("PriceFetcher.xlsm").Activate
Application.Goto Reference:="ticker"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Wait (Now + TimeValue("0:00:01"))
Application.Goto Reference:="PRICE_RANGE"
Application.CutCopyMode = False
Selection.Copy
Windows("HistData.xlsm").Activate
Application.Goto Reference:="root1"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'
' Ticker 2 Procedure
Windows("HistData.xlsm").Activate
Application.Goto Reference:="tick2"
Application.CutCopyMode = False
Selection.Copy
Windows("PriceFetcher.xlsm").Activate
Application.Goto Reference:="ticker"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Wait (Now + TimeValue("0:00:01"))
Application.Goto Reference:="PRICE_RANGE"
Application.CutCopyMode = False
Selection.Copy
Windows("HistData.xlsm").Activate
Application.Goto Reference:="root2"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Ticker 1 Procedure
Windows("HistData.xlsm").Activate
Application.Goto Reference:="tick1"
Application.CutCopyMode = False
Selection.Copy
Windows("PriceFetcher.xlsm").Activate
Application.Goto Reference:="ticker"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Wait (Now + TimeValue("0:00:01"))
Application.Goto Reference:="PRICE_RANGE"
Application.CutCopyMode = False
Selection.Copy
Windows("HistData.xlsm").Activate
Application.Goto Reference:="root1"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'
' Ticker 2 Procedure
Windows("HistData.xlsm").Activate
Application.Goto Reference:="tick2"
Application.CutCopyMode = False
Selection.Copy
Windows("PriceFetcher.xlsm").Activate
Application.Goto Reference:="ticker"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.Wait (Now + TimeValue("0:00:01"))
Application.Goto Reference:="PRICE_RANGE"
Application.CutCopyMode = False
Selection.Copy
Windows("HistData.xlsm").Activate
Application.Goto Reference:="root2"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False