Private sub to Normal sub

Vbalearner85

Board Regular
Joined
Jun 9, 2019
Messages
139
Office Version
  1. 2016
Platform
  1. Windows
Hi Friends,

I have below private macro(in the particular sheet) which works to update Timestamp in column B for every formula driven data change in column A cells . Macro works fine, but does not let excel close (reopens when closed) as well as causes exceptions to run Python script on same excel file for some other data needs. I have many other macros in same file.but they do not cause any excel/python issues

My question is can we write a normal sub/module macro to replace below macro but have the same functionality(update Timestamp in column B for every formula driven data change in column A cells - Note the data chnage in column A is formula driven, not manual input)


Private Sub Worksheet_Calculate()
Dim Cell As Range
For Each Cell In Range("A1:A142")
If Cell.Value <> Cell.Offset(0, 8).Value Then
Cell.Offset(0, 1).Value = Now
Cell.Offset(0, 8).Value = Cell.Value
End If
Next
Columns("B:B").EntireColumn.AutoFit
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You can have code in a standard code module that would do the data manipulation and calculation like the event code, but it would have to be either be called by an event code or manually activated. The Calculate event is used in place of change event because Excel will does not consider formula derived values as a change event, even though the values do change. But volatile formulas would wreak havoc on the system if Excel did try to acknowledge those changes. So basically, your choice is try to do it with manual control or do it with the calculate event.
 
Upvote 0
Sir..my file already does some have lifting per sec data timer macros...copies data per sec.....seems fine until now to the size of ~ 250 MB data(although a save a copy by name "ddmmyy" and yet retain original file as 300kb towards the end of day)

Please guide me how we can put it in a change event in a standard module and yet do the same "timestamp function on formula driven data change"....let me give it a try...Thanks
 
Upvote 0
Try it with these modifications.

VBA Code:
Private Sub Worksheet_Calculate()
Dim Cell As Range
Application.EnableEvents = False
For Each Cell In Range("A1:A142")
    If Cell.Value <> Cell.Offset(0, 8).Value Then
        Cell.Offset(0, 1).Value = Now
        Cell.Offset(0, 8).Value = Cell.Value
    End If
Next
Columns("B:B").EntireColumn.AutoFit
Application.EnableEvents = True
End Sub
 
Upvote 0
Quick question...will this go in a standard module?? and how is this referencing to work only on particular worksheet for Eg "Data" sheet
 
Upvote 0
Quick question...will this go in a standard module?? and how is this referencing to work only on particular worksheet for Eg "Data" sheet
It is a modification to your existing code and goes in the same code module. But it prevents the changes from triggering other events until the time stamp and column I have been updated.
 
Upvote 0
Thanks sir...looks like this is now working as desired. Also did some tweaks in Python module....working fines as of now..


Thanks so much. Will post final observations after testing on Monday.

Regards
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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