+ Reply to Thread
Results 1 to 2 of 2

Run-time Error '1004': An unexpected error has occurred

  1. #1
    Registered User
    Join Date
    11-23-2016
    Location
    Indo
    MS-Off Ver
    2016
    Posts
    1

    Question Run-time Error '1004': An unexpected error has occurred

    Hello Guys,
    i am new to macro coding, and i got a problem with this excel.
    Everytime i add new code to row after 256 and Click the button "Click to download data", it will pop up an error "Run-time Error '1004': An unexpected error has occurred".
    Anyone please help me how to fix this error.
    This is the file: https://www.dropbox.com/s/g2ywtxf4ru...heet.xlsm?dl=1


    Code in macro:
    Sub GetData()

    Dim QuerySheet As Worksheet
    Dim DataSheet As Worksheet
    Dim qurl As String
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.Calculation = xlCalculationManual

    Set DataSheet = ActiveSheet

    Range("C7").CurrentRegion.ClearContents
    i = 7
    qurl = "http://download.finance.yahoo.com/d/quotes.csv?s=" + Cells(i, 1)
    i = i + 1
    While Cells(i, 1) <> ""
    qurl = qurl + "+" + Cells(i, 1)
    i = i + 1
    Wend
    qurl = qurl + "&f=" + Range("C2")
    Range("c1") = qurl
    QueryQuote:
    With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("C7"))
    .BackgroundQuery = True
    .TablesOnlyFromHTML = False
    .Refresh BackgroundQuery:=False
    .SaveData = True
    End With

    j = Range("A7").End(xlDown).Row

    For k = 7 To j

    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc. Common Stoc", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc. Common St", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc. Co St", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc. Co", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc. (The)", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc. Com", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Inc.", "")
    Cells(k, "C").Value = Replace(Cells(k, "C").Value, ", Incorporated C", "")

    Next

    Range("C7").CurrentRegion.TextToColumns Destination:=Range("C7"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=True, Space:=False, other:=False


    'turn calculation back on
    Application.Calculation = xlCalculationAutomatic
    Application.DisplayAlerts = True
    ' Range("C7:H6000").Select
    ' Selection.Sort Key1:=Range("C8"), Order1:=xlAscending, Header:=xlGuess, _
    ' OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Columns("C:C").ColumnWidth = 25
    Rows("7:6000").RowHeight = 16
    Columns("J:J").ColumnWidth = 8.5
    Range("h2").Select

    End Sub
    Last edited by andywangrex; 11-23-2016 at 02:49 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time Error '1004': An unexpected error has occurred

    Please wrap up your code with code tags as per forum's rule.

    This link might help

    http://www.excelforum.com/excel-prog...wnloading.html

    There are some people who claimed to have to downloaded any amount of data with out daily restrictions, but I believe most sites which allow people to download massive data have some kind of restrictions.
    Your case might not be the same; that is, there is an error on your code, like wrong stock symbol, but I still believe no site will allow a free ride all day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Not Able To Run Web Queries ("An unexpected error has occurred")
    By ericrichard25 in forum Excel General
    Replies: 0
    Last Post: 11-15-2014, 06:40 PM
  2. [SOLVED] Run-time error '1004': An unexpected error has occurred
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2014, 05:54 AM
  3. [SOLVED] Macro with Solver. An unexpected internal error occurred, or available memory
    By sofiaventura in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-26-2013, 04:24 PM
  4. Solver: An unexpected internal error occurred, or available memory
    By Chad in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2013, 05:31 AM
  5. Replies: 0
    Last Post: 04-06-2006, 02:45 AM
  6. New to VBA, getting unexpected error 1004
    By Teodomiro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-04-2006, 11:50 AM
  7. Unexpected error 1004 when using workbooks.open
    By AHD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2005, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1