Consulting

Results 1 to 4 of 4

Thread: Solved: External Data Requery

  1. #1

    Solved: External Data Requery

    I keep getting an Excel error when I run the following code. The external data query is extrememly large and the macro does not seem to be waiting for the data to refresh.

    Error Message: The cell or chart you are trying to change is protected and therefore read-only.

    Any suggestions much appreicated.

    Thanks,
    Rich

    [vba]Sub Button17_Click()
    'On Error Resume Next
    Application.ScreenUpdating = False
    Sheets("RTS_Details").Visible = True
    Sheets("Daily_Report").Visible = False
    Sheets("User_Report").Visible = False
    Sheets("RTS_Details").Select
    Sheets("RTS_Details").Unprotect
    Range("H16").Select
    Selection.QueryTable.Refresh BackgroundQuery:=True
    Range("F5").Select
    Selection.AutoFill Destination:=Range("F5:F15000"), Type:=xlFillValues
    Range("H5").Select
    Selection.AutoFill Destination:=Range("H5:H15000"), Type:=xlFillValues
    Sheets("RTS_Details").Select
    Sheets("RTS_Details").Protect
    Application.ScreenUpdating = True
    End Sub[/vba]

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    from help:
    BackgroundQuery Optional Variant. Used only with QueryTables that are based on the results of a SQL query. True to return control to the procedure as soon as a database connection is made and the the query is submitted. The QueryTable is updated in the background. False to return control to the procedure only after all data has been fetched to the worksheet. If this argument isn't specified, the setting of the BackgroundQuery property determines the query mode.

    So change

    Selection.QueryTable.Refresh BackgroundQuery:=True
    to
    Selection.QueryTable.Refresh BackgroundQuery:=False

    ?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    <deleted>
    ____________________________________________
    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

  4. #4
    p45cal, thanks changing Selection.QueryTable.Refresh BackgroundQuery:=False worked.

Posting Permissions

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