AfterRefresh for multiple querytables

tcarter963

New Member
Joined
Aug 3, 2006
Messages
38
I would like to get this to work with multiple querytables on multiple sheets but I'm not sure as to where to start.

Class Module
Public WithEvents qt As QueryTable

Private Sub qt_AfterRefresh(ByVal Success As Boolean)

Dim LastRowColumnT As Long
Dim Selection1 As Range
Dim Selection2 As Range

LastRowColumnT = Range("T301").End(xlUp).Row
Set Selection1 = Range("Y8:AF13")
Set Selection2 = Range("Y8:AF" & LastRowColumnT)
Set Selection3 = Range("U5:W10")
Set Selection4 = Range("U5:W" & LastRowColumnT)

Application.ScreenUpdating = False

On Error GoTo ErrHandler:
ErrHandler:
If Err.Number = 1004 Then
MsgBox "Calculations won't autofill until there are at least 5 time points", vbInformation
Exit Sub
End If

If Success Then Selection3.AutoFill Destination:=Selection4

If Success Then Selection1.AutoFill Destination:=Selection2


Application.ScreenUpdating = True

End Sub

module

Dim X As New Class1

Sub Auto_Open()
Set X.qt = ThisWorkbook.Sheets(2).QueryTables(1)


End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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