Run VBA code using event (TableUpdate)

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
217
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

I have the following code that I'd like to run when my table is refreshed using PowerQuery, but not sure how to use it within the event. Any suggestion?

VBA Code:
Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
  
  Dim wrksht4 As Worksheet
  Dim i As Integer
   
  Set wrksht4 = ActiveWorkbook.Worksheets("EDPlannedOrders")
    With wrksht4
     'Find the last non-blank cell in column A(1)
      LRow = .Cells(Rows.Count, 9).End(xlUp).Row
      
      i = LRow
        .Cells(LRow + 1, 9) = Format(Date, "YYYY/MM/DD")
        .Cells(LRow + 1, 10) = .Cells(1, 6).Value
    End With

End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
VBA Code:
Option Explicit
Private WithEvents QT As QueryTable
Private Sub Workbook_Open()
       Set QT = Worksheets("Sheet1").ListObjects("QueryTableName").QueryTable
End Sub
Private Sub QT_AfterRefresh(ByVal Success As Boolean)
  Dim wrksht4 As Worksheet
  Dim i As Integer
  
  Set wrksht4 = ActiveWorkbook.Worksheets("EDPlannedOrders")
    With wrksht4
     'Find the last non-blank cell in column A(1)
      LRow = .Cells(Rows.Count, 9).End(xlUp).Row
     
      i = LRow
        .Cells(LRow + 1, 9) = Format(Date, "YYYY/MM/DD")
        .Cells(LRow + 1, 10) = .Cells(1, 6).Value
    End With
End Sub

You should replace the actual query table name and referring sheet.
 
Upvote 1
Solution

Forum statistics

Threads
1,214,601
Messages
6,120,460
Members
448,965
Latest member
grijken

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