Excel VBA Table Auto Trigger Macro based on row added

Vigash

New Member
Joined
Aug 26, 2022
Messages
21
Office Version
  1. 2013
Platform
  1. Windows
Hi Team,

I have connected my table to MySQL Database. If any data is updated in the database I will get it in an excel table.

If any data is added newly I want to trigger a macro. How it's possible? I tried the worksheet Change event but did not trigger the macro which I stored in Module.

Any help, Highly appreciated.

Thanks in advance
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Worksheet change event is usually only triggered by a user input change, not by a database update.
A common way round this is to use the worksheet calculate event. To get this to work you need to pick a cell that will alwyas change with every update, often this is the time stamp of the update.
Then you put a simple equation in another spare cell that does a calculation using this cell. e.g. assuming there is a time stamp in cell A1
you could this equation in Z1:
Excel Formula:
=A1+1
This forces excel to do a recalculation of that cell which will trigger the worksheet calculate event
 
Upvote 0
Worksheet change event is usually only triggered by a user input change, not by a database update.
A common way round this is to use the worksheet calculate event. To get this to work you need to pick a cell that will alwyas change with every update, often this is the time stamp of the update.
Then you put a simple equation in another spare cell that does a calculation using this cell. e.g. assuming there is a time stamp in cell A1
you could this equation in Z1:
Excel Formula:
=A1+1
This forces excel to do a recalculation of that cell which will trigger the worksheet calculate event
Hi offthelip,

Thank you for your help. I did a turnaround and it worked.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Me.ListObjects("StockOut").Range.Rows.Count) Is Nothing Then

Call lastrowfinder

End If

End Sub

Whenever row count changes in the table it will trigger my macro.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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