Write now I am changing the stock symbol every time by clicking on my macro created button and entering the stock symbol in an input box. Suppose I have 10 stock symbols and I wanted to loop through each stock symbol and produce results in separate sheets. 10 different sheets for 10 different symbols. How am I supposed to overcome this problem. This process I am doing is very repetitive so any ideas? In real I have 1000 stock symbols.
Here's my code from which I am fetching my data and it looks like this right now.
Option Explicit
Sub Changestockproperties()
'
' Changestockproperties Macro
'
'
With ActiveWorkbook.Connections("NAME"). _
OLEDBConnection
.BackgroundQuery = True
.CommandText = Array( _
"Select Quotedate, StockSymbol, COnvert(Float,ClosePrice) As ClosePrice, COnvert(Float,TRInverse) AS TRInverse, " & Chr(13) & "" & Chr(10) & "CO" _
, _
"nvert(Float,Osc_1VI) As Osc_1VI, Convert(Float,HeatmapTrans) as HeatmapTrans" & Chr(13) & "" & Chr(10) & "from FormulaHeatmapOscilator where St" _
, "ockSymbol='" & InputBox("Enter Stock Symbol"), "' order by quotedate")
.CommandType = xlCmdSql
.Connection = Array( _
"OLEDB;Provider=NAME;Password=NAME;Persist Security Info=True;Extended Properties=""DRIVER=SQL Server;SERVER=NAME" _
, _
"3;UID=sa;APP=Microsoft Office 2013;WSID=NAME;DATABASE=NAME"";Use Procedure for Prepare=1;Auto Transla" _
, _
"te=True;Packet Size=4096;Workstation ID=NAME;Use Encryption for Data=False;Tag with column collation when possible=Fa" _
, "lse")
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("NAME")
.Name = "NAME"
.Description = ""
End With
ActiveWorkbook.Connections("NAME").Refresh
End Sub
Adding range of my sheet to dictionary.
Option Explicit
Public Sub ChangeStockSymbol()
Dim d As Scripting.Dictionary
Dim r As Excel.Range
Dim c As Excel.Range
Set d = New Scripting.Dictionary
Set r = Range("A1:B1311")
For Each c In r.Cells
d.Add CStr(c.Address), c.Value
Next c
End Sub