Hello everyone,
I have multiple CSV files with outdated historical stock prices. In order to update data, I need to download missing prices for the last several days and paste them into corresponding files (file name same as sheet name same as stock symbol), between rows 1 and 2, cells B to H.
I have a MasterFile with macro that downloads historical stock prices for a single stock at a time, you have to update stock symbol in the cell B4 manually and press button every time to download new stock data. Historical price data downloaded in chronological descending order into Sheet1, range A14 to G14 (for a single day). So the last day price is in the row14, previous date row15 etc. The name of the sub is “Sub GetHistData()”.
The stock symbol is entered into cell B4 (NameOfStock = .Range("StockSymbol")).
I want to modify code or to write another macro so that I could download data for multiple stocks automatically. Lets say I want to keep list of the stock symbols in the column K.
The next question is how to copy several rows of data, cells A to G (for every bunch of files, number of the rows will be different, so I will need input box to indicate number of the rows to be copied) and insert them between row1 and row2, cells B to H in the CSV file with the name same as stock symbol, AAPL.csv for example.
Is there any way to modify code (beginning part of which follows below) or to write second macro that changes stock symbols in the cell B4 and runs “Sub GetHistData()”, so that I could download historical data of multiple stocks?
I would be grateful for any help.
The beginning of the code is as it follows:
I have multiple CSV files with outdated historical stock prices. In order to update data, I need to download missing prices for the last several days and paste them into corresponding files (file name same as sheet name same as stock symbol), between rows 1 and 2, cells B to H.
I have a MasterFile with macro that downloads historical stock prices for a single stock at a time, you have to update stock symbol in the cell B4 manually and press button every time to download new stock data. Historical price data downloaded in chronological descending order into Sheet1, range A14 to G14 (for a single day). So the last day price is in the row14, previous date row15 etc. The name of the sub is “Sub GetHistData()”.
The stock symbol is entered into cell B4 (NameOfStock = .Range("StockSymbol")).
I want to modify code or to write another macro so that I could download data for multiple stocks automatically. Lets say I want to keep list of the stock symbols in the column K.
The next question is how to copy several rows of data, cells A to G (for every bunch of files, number of the rows will be different, so I will need input box to indicate number of the rows to be copied) and insert them between row1 and row2, cells B to H in the CSV file with the name same as stock symbol, AAPL.csv for example.
Is there any way to modify code (beginning part of which follows below) or to write second macro that changes stock symbols in the cell B4 and runs “Sub GetHistData()”, so that I could download historical data of multiple stocks?
I would be grateful for any help.
The beginning of the code is as it follows:
VBA Code:
Sub GetHistData()
Dim DesiredFields As Variant, NameOfStock As String
Dim RangeField As String, RangeUnit As String, s As Variant, IntervalField As String, DateOrder As Integer
Dim DateOffset As Double, ErrorMsg As String, FilterFilterOutRows As Boolean
Dim BeginDate As Date, EndDate As Date
'With ActiveSheet
With Sheets("Sheet1")
'READ THE STOCK SYMBOL:
NameOfStock = .Range("StockSymbol")
'READ THE RANGE
RangeField = CStr(.Range("Range"))