Using VBA I import a csv file into excel from Yahoo Finance containing 7 comma separated values per row. I would like to only import the first and 5th comma separated value of each row. Currently I import the entire csv, extract it to columns and then delete the unwanted columns. However this does not suffice for future uses of this import. How can I make a selection of the columns I want to import??
Current code:
qURL = "http://ichart.finance.yahoo.com/table.csv?s=" & Symbol & "&a=" & Month(Startdate) - 1 & "&b=" & Day(Startdate) & _
"&c=" & Year(Startdate) & "&d=" & Month(Enddate) - 1 & "&e=" & Day(Enddate) & "&f=" & Year(Enddate) & "&g=" & QuoteInterval & "&ignore=.csv"
With Sheets(2).QueryTables.Add(Connection:="URL;" & qURL, Destination:=ActiveCell.Offset(1, 0))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Sheets(2).Range("A2:A" & Lastrow).TextToColumns Destination:=Sheets(2).Range("A2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, other:=False
Columns(2).EntireColumn.Delete
Columns(2).EntireColumn.Delete
Columns(2).EntireColumn.Delete
Columns(3).EntireColumn.Delete
Columns(3).EntireColumn.Delete
Range("A3:A" & Lastrow).NumberFormat = "dd mmm yy"
Range("B3:B" & Lastrow).NumberFormat = "0.00"