VBA Event code

Vigash

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

I am working on a worksheet event. My requirement is whenever new data is added to the table I am trying to call a macro.

(My table has been connected to Mysql database)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Records As Range
Set Records = Range("Stockout")
If Not Application.Intersect(Records, Range(Target.Address)) Is Nothing Then
Call Module3.lastrow_value
End If
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.ListObjects("StockOut").ListRows.Count) Is Nothing Then
Call Module3.lastrow_value
End If
End Sub

Kindly suggest which one is right to achieve my expectation.

Regards,
Vigash
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Which one works for you?


It's possible worksheet_change event would not work in this scenario, how is the data added
 
Upvote 0
Which one works for you?


It's possible worksheet_change event would not work in this scenario, how is the data added
Data added to excel table from mysql data base table via odbc connection..

Kindly help me to find ways to trigger macro when new data added to my table...
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Records As Range
Set Records = Range("Stockout")
If Not Application.Intersect(Records, Range(Target.Address)) Is Nothing Then
Call Module3.lastrow_value
End If
End Sub

This code seems to be working for me... But the issue is there is difference in output when I manually run lastrow_value macro I am getting different output which is accurate but when automatically trigger same macro it's giving different.. So my understanding is whether there is issue with event itself.... Correct me if I am wrong
 
Upvote 0
If the event is running the macro, then it is doing what it should.

Check out
 
Upvote 0
Is the data linked from SQL?
If so, I don't think that will trigger a Worksheet_Change event procedure to run.
You would need to use something like Worksheet_Calculate instead (just note that there is no "Target" date parameter with that event code - it cannot tell which range changed, only that there was some recalculation somewhere on the worksheet).
 
Upvote 0
Solution

Forum statistics

Threads
1,224,835
Messages
6,181,245
Members
453,026
Latest member
cknader

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