Forum Discussion
Can VBA Event "Change" work if the target address cell is a formula that changes dynamically?
- Aug 23, 2022
I wouldn't count myself as a VBA expert either!
What I have tried is to move the event handler to the 'Gallons' Sheet:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Worksheets("Gallons").ListObjects("Table1").Range) Is Nothing Then ClearManualInput End Sub
and placed the instruction to clear contents in a general code module
Sub ClearManualInput() Range("ManualEntries").ClearContents End Sub
I hope this at least represents a step in the right direction.
The point may be that the evaluation of worksheet formulae does not trigger change events. It is user input and changes made by VBA that will do that. The worksheet changes that you can trap are those made to the tables on the 'Gallons' and 'Sample' sheets (formally converting them to Excel Tables might improve the workbook usability)
The other part of your query would involve SheetSelectionChange which is a method within the module ThisWorkbook.
In my original file, the gallon and sample are indeed tables, but with a lot of columns, but there's so much happening in every column of those.
Can you help me a TableUpdate macro, in my sample file, so that I can try replicating it?
My VBA knowledge is just surface level.
- PeterBartholomew1Aug 23, 2022Silver Contributor
I wouldn't count myself as a VBA expert either!
What I have tried is to move the event handler to the 'Gallons' Sheet:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Worksheets("Gallons").ListObjects("Table1").Range) Is Nothing Then ClearManualInput End Sub
and placed the instruction to clear contents in a general code module
Sub ClearManualInput() Range("ManualEntries").ClearContents End Sub
I hope this at least represents a step in the right direction.
- Nishkarsh31Aug 29, 2022Brass ContributorThank you sir, this was really helpful