Hi,
I have a folder of CSV files downloaded from yahoo finance and I have written code to get data from each of them. It took a long time and is a lengthy process if I want to add another 5-10 files. The code is below. The first block is some preliminary set up then the 2nd, 3rd and 4th are gathering data. I have about 10 CSV files I'm doing this for. Is there a way to make this automation even more automated. It would be good if I could just drop a CSV file into the folder, ran the macro and Excel picked up there was a new file in there and got the data from it.
Thanks for any help
I have a folder of CSV files downloaded from yahoo finance and I have written code to get data from each of them. It took a long time and is a lengthy process if I want to add another 5-10 files. The code is below. The first block is some preliminary set up then the 2nd, 3rd and 4th are gathering data. I have about 10 CSV files I'm doing this for. Is there a way to make this automation even more automated. It would be good if I could just drop a CSV file into the folder, ran the macro and Excel picked up there was a new file in there and got the data from it.
Thanks for any help
VBA Code:
Dim xjo As Workbook
Set xjo = Workbooks.Open("C:\Users\Username\Desktop\Asset Allocation\Stock Data\Monthly\^AXJO.csv", True, True)
Dim lrow As Long
lrow = Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Activate
Worksheets("Sheet1").Range("A1:A" & lrow).Formula = xjo.Worksheets("^AXJO").Range("A1:A" & lrow).Formula
Range("A1:A" & lrow).NumberFormat = "dd/mm/yyyy"
Worksheets("Sheet1").Range("B2:B" & lrow).Formula = xjo.Worksheets("^AXJO").Range("F2:F" & lrow).Formula
Range("B1").Value = "XJO"
Workbooks("^AXJO").Close
Dim bboz As Workbook
Set bboz = Workbooks.Open("C:\Users\Username\Desktop\Asset Allocation\Stock Data\Monthly\BBOZ.AX.csv", True, True)
ThisWorkbook.Activate
Worksheets("Sheet1").Range("C2:C" & lrow).Formula = bboz.Worksheets("BBOZ.AX").Range("F2:F" & lrow).Formula
Range("C1").Value = "BBOZ"
Workbooks("BBOZ.AX").Close
Dim gear As Workbook
Set gear = Workbooks.Open("C:\Users\Username\Desktop\Asset Allocation\Stock Data\Monthly\GEAR.AX.csv", True, True)
ThisWorkbook.Activate
Worksheets("Sheet1").Range("D2:D" & lrow).Formula = gear.Worksheets("GEAR.AX").Range("F2:F" & lrow).Formula
Range("D1").Value = "GEAR"
Workbooks("GEAR.AX").Close
Dim csl As Workbook
Set csl = Workbooks.Open("C:\Users\Username\Desktop\Asset Allocation\Stock Data\Monthly\CSL.AX.csv", True, True)
ThisWorkbook.Activate
Worksheets("Sheet1").Range("E2:E" & lrow).Formula = csl.Worksheets("CSL.AX").Range("F2:F" & lrow).Formula
Range("E1").Value = "CSL"
Workbooks("CSL.AX").Close
Last edited by a moderator: