By The following code I import data from a morningstar.com CSV file, the data split by commas. The problem that some of the data contain a comma.
For example, "XX, XXX". the result of this situation is:
cell1(X1,Y1)="XX cell(X1,Y2)=XXX" instead of: cell1(X1,Y1)=XX,XXX
My VBA
Sub GetKeyRatios()
Dim URL As String, csv As String, Lines, Values
Dim i As Long, j As Long, WinHttpReq As Object
Dim rngStart As Range
URL = "http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNYS:JNJ®ion=usa&culture=en-US&cur=USD&order=asc"
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send
csv = WinHttpReq.responseText
Lines = Split(csv, vbLf)
Set rngPaste = Sheets("KeyRatios").Range("A1")
For i = 0 To UBound(Lines)
Values = Split(Lines(i), ",")
For j = 0 To UBound(Values)
rngPaste.Offset(i, j).Value = Values(j)
Next j
Next i
End Sub
Is there any way to do this?
example

.csvdirectlyworkbooks.Open("http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNYS:JNJ®ion=usa&culture=en-US&cur=USD&order=asc")- Slai