Historical price data download with data transfer between the files.

dilshod_k

Board Regular
Joined
Feb 13, 2018
Messages
79
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:

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"))
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top