How to stop table created from the Power Query Editor from refreshing twice

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. Windows
I have the code below that refreshes a Power Query Editor generated table and then does some things to the table. The problem I have is when the code is run, it returns the table back to it's refreshed state without my changes that I made, even though the refresh is the first line of the code. How can I stop it from refreshing when the changes are made? Thanks, SS

VBA Code:
Sub Update_TBL_List()
'
' Update TBL_List Macro
'

'
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        .CutCopyMode = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    End With

    Worksheets("Table Quick Access").ListObjects("TBL_List").Refresh
  
    Columns("D:D").Select
    Selection.Delete Shift:=xlToLeft

    Range("A1").Value2 = "Table File Path"
    Range("C1").Value2 = "Table Name"
    
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    
    Application.Calculation = xlAutomatic

    Range("B2").Select
    ActiveCell.Formula2R1C1 = _
        "=IFERROR(MID(CELL(""address"",INDIRECT([@[Table Name]])),SEARCH("".xlsm]"",CELL(""address"",INDIRECT([@[Table Name]])),1)+6,(SEARCH(""'!$"",CELL(""address"",INDIRECT([@[Table Name]])),1)-(SEARCH("".xlsm]"",CELL(""address"",INDIRECT([@[Table Name]])),1)+6))),""Table Quick Access"")"

    Range("A2").Select
    ActiveCell.Formula2R1C1 = "=CELL(""address"",INDIRECT([@[Table Name]]))"
    
    Range("A2").Select
    Selection.AutoFill Destination:=Range("TBL_List[Table File Path]"), Type:= _
        xlFillDefault

    Columns("A:A").ColumnWidth = 64
    Columns("B:C").ColumnWidth = 32
    Columns("D:E").ColumnWidth = 12
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
        .CutCopyMode = False
        .DisplayAlerts = False
'        .Calculation = xlAutomatic
    End With

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Refreshing a PQ query is asynchronous by default, so if your code is fast enough the code finishes before the query. Right-click the query, choose properties and uncheck the async box.
 
Upvote 0
Solution
Refreshing a PQ query is asynchronous by default, so if your code is fast enough the code finishes before the query. Right-click the query, choose properties and uncheck the async box.
Perfect, this is exactly what I needed. Thank you...
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top