Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jon Jon is offline
external usenet poster
 
Posts: 183
Default Sort CSV file from Yahoo Finance Query

I got the following bit of code on this discussion forum(which I have
modified slightly). It is supposed to pull the historical stock prices off of
yahoo finance. The problem is that it imports entire rows of .csv info into a
single cell. How do I sort the data into columns? I have tried the
textfilecommadelimiter property with no success. Thanks a lot.

Jon


'Retrieve Variables to place inside a URL String
Sub getVars()
'Declare Variables for URL
Dim myURL As String
Dim Ticker As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String
Dim f As String
Dim g As String

'Assign values from Cells to variables
Ticker = Cells(1, 1).Value
a = Cells(2, 1).Value
Cells(2, 1).Select
b = Cells(3, 1).Value
c = Cells(4, 1).Value
d = Cells(5, 1).Value
e = Cells(6, 1).Value
f = Cells(7, 1).Value
g = Cells(8, 1).Value

'Append variables of URL to one string myURL
myURL = "http://table.finance.yahoo.com/table.csv?s="
myURL = myURL + Ticker + "&a="
myURL = myURL + a + "&b="
myURL = myURL + b + "&c="
myURL = myURL + c + "&d="
myURL = myURL + d + "&e="
myURL = myURL + e + "&f="
myURL = myURL + f + "&g="
myURL = myURL + g

'Test Display string myURL in a cell
'Cells(15, 1).Value = myURL

'Some code i copied that will display the WHOLE HTML page in sheet 2
Dim WebCopy As Object
Set WebCopy = Sheets("Sheet2")

WebCopy.Cells.Clear

With WebCopy.QueryTables.Add(Connection:="URL;" & myURL,
Destination:=WebCopy.Range("A1"))
..BackgroundQuery = True
..TablesOnlyFromHTML = True
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True

..Refresh BackgroundQuery:=False
..SaveData = True
End With

'With Application
'.ScreenUpdating = True
'.DisplayAlerts = True
'.Calculation = xlCalculationAutomatic
'.Goto Range("A1"), True
'End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Sort CSV file from Yahoo Finance Query

did you experiment with the text to columns menu selection? if you get that
to work, you can record a macro while you do it. you need to know how the
file is delimited.

--


Gary


"Jon" wrote in message
...
I got the following bit of code on this discussion forum(which I have
modified slightly). It is supposed to pull the historical stock prices off
of
yahoo finance. The problem is that it imports entire rows of .csv info
into a
single cell. How do I sort the data into columns? I have tried the
textfilecommadelimiter property with no success. Thanks a lot.

Jon


'Retrieve Variables to place inside a URL String
Sub getVars()
'Declare Variables for URL
Dim myURL As String
Dim Ticker As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String
Dim f As String
Dim g As String

'Assign values from Cells to variables
Ticker = Cells(1, 1).Value
a = Cells(2, 1).Value
Cells(2, 1).Select
b = Cells(3, 1).Value
c = Cells(4, 1).Value
d = Cells(5, 1).Value
e = Cells(6, 1).Value
f = Cells(7, 1).Value
g = Cells(8, 1).Value

'Append variables of URL to one string myURL
myURL = "http://table.finance.yahoo.com/table.csv?s="
myURL = myURL + Ticker + "&a="
myURL = myURL + a + "&b="
myURL = myURL + b + "&c="
myURL = myURL + c + "&d="
myURL = myURL + d + "&e="
myURL = myURL + e + "&f="
myURL = myURL + f + "&g="
myURL = myURL + g

'Test Display string myURL in a cell
'Cells(15, 1).Value = myURL

'Some code i copied that will display the WHOLE HTML page in sheet 2
Dim WebCopy As Object
Set WebCopy = Sheets("Sheet2")

WebCopy.Cells.Clear

With WebCopy.QueryTables.Add(Connection:="URL;" & myURL,
Destination:=WebCopy.Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True

.Refresh BackgroundQuery:=False
.SaveData = True
End With

'With Application
'.ScreenUpdating = True
'.DisplayAlerts = True
'.Calculation = xlCalculationAutomatic
'.Goto Range("A1"), True
'End With

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel web query does not import table (from yahoo finance) correct Jerome Excel Discussion (Misc queries) 1 April 19th 09 01:21 PM
Pulling stock quotes from Yahoo Finance into a spreadsheet [email protected] Excel Discussion (Misc queries) 1 November 8th 06 10:09 AM
Web queries & Yahoo! Finance cwhaley Excel Discussion (Misc queries) 1 February 2nd 06 12:31 AM
Historical Stock Quotes - Yahoo Finance Jason Excel Programming 4 July 4th 05 12:40 AM
vba yahoo! finance Arun Ram Kumaran Excel Programming 1 July 25th 03 01:04 AM


All times are GMT +1. The time now is 08:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"