Consulting

Results 1 to 3 of 3

Thread: 3 pairs of If and end if

  1. #1
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location

    3 pairs of If and end if

    In J1, put ^dji
    whether put w or m in I1, both give daily data
    [VBA]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
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    Quote Originally Posted by asdzxc
    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?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    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.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •