PDA

View Full Version : 3 pairs of If and end if



asdzxc
05-22-2012, 05:45 AM
In J1, put ^dji
whether put w or m in I1, both give daily data
StrURL = "URL;http://ichart.finance.yahoo.com/table.csv?s=" & [Sheet1!J1].Value
If Range("I1").Value = d Then
StrURL = StrURL & "&a=3&b=15&c=2012&d=06&e=6&f=2013" _
& "&g=d&ignore=.xlsx"
End If
If Range("I1").Value = w Then
StrURL = StrURL & "&a=10&b=13&c=2011&d=06&e=6&f=2013" _
& "&g=w&ignore=.xlsx"
End If
If Range("I1").Value = m Then
StrURL = StrURL & "&a=10&b=13&c=2009&d=06&e=6&f=2013" _
& "&g=m&ignore=.xlsx"
End If

With ActiveSheet.QueryTables.Add(Connection:=StrURL, Destination:=Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub

Bob Phillips
05-22-2012, 06:01 AM
In J1, put ^dji
whether put w or m in I1, both give daily data

What?

Do you want to say that in a way that makes some sense?

BrianMH
05-22-2012, 06:18 AM
Are d, w and m variables? If not then you need to put them in quotes. Setting Option Explicit will help you avoid these issues.