Macro command to refresh after cell value changes

vinsis300

New Member
Joined
Jun 30, 2014
Messages
8
Hi guys, new to the forums. Been searching the web for hours to find a way to refresh web queries for only the cells that have changed values. I created several sheets to run queries and have them set to update when the values on my main sheet change for particular cells. In my macro, everything runs fine to the point where I need the macro to refresh and I have tried ThisWorkbook.RefreshAll but there are 50 worksheets and not all of them need to be refreshed. Is there basic code to have the refresh only for the cells that have changed values? When I stop the macro at any point, the cells that have new values refresh their respective queries, but during the macro it won't do them.
 
All statements within the Case will run so you just need to have both refreshes in the same Case. e.g.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target.Address
    Case "$A$2"
        QueryTables("MSN query_1").refresh
        QueryTables("yahoo risk 2").refresh
    Case "$B$2"
        ' Do Something else
    End Select
End Sub
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
All statements within the Case will run so you just need to have both refreshes in the same Case. e.g.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target.Address
    Case "$A$2"
        QueryTables("MSN query_1").refresh
        QueryTables("yahoo risk 2").refresh
    Case "$B$2"
        ' Do Something else
    End Select
End Sub

Aahhhhh! I see. Thanks a million for your help. I'll try the code in a bit and let you know the outcome.
 
Upvote 0
Teeroy, no luck. Here's the start of my code:

Code:
Sub RefreshCopyPaste()

Application.EnableEvents = True
'
' copycolumn Macro
'

'
    sheets("Funds").Select
    Range("A1").Select
    Selection.Copy
    
    
' Active cell progression
'
'
    sheets("All Asset Class Data").Select
    ActiveCell.Select
    Range("A1").Select
    ActiveSheet.Paste
    Range("A1:B1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .mergecells = False
    End With
    Selection.Merge
    sheets("Tickers").Select
    'Range(Selection, Selection.End(xlDown)).Select
    'Application.CutCopyMode = False
    'Selection.ClearContents
    Range("A1").Select
    sheets("Funds").Select
    Range("A:A").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    sheets("Tickers").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Here is where the refresh should occur and here's how I have it coded in the other spreadsheet where the changes happen:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target.Address
    Case "$A$2"
        QueryTables("MSN A2").refresh
        QueryTables("Yahoo A2").refresh
    Case "$B$2"
        QueryTables("MSN A3").refresh
        QueryTables("Yahoo A3").refresh
    End Select
    
    End Sub

Not sure why it's not refreshing or if I have things to enable events in the wrong place.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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