VBA not picking up Formula populated cells need a new trigger?

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
Hi All,

i have the below code which runs when a cells is populated (but only works when manually populated). i have cells that are either manually populated (which it words fine for) and some that are populated via a formula (which is does not work for). do i need to change the trigger to enable the VBA to pick up the cells populated via a formula? preferably an automatic solution would be best as these cells are hidden and is used to flag issues etc.

Code:
Private Sub Worksheet_Open(ByVal Target As Range)    If Target.Column = 11 Or Target.Column = 13 Then 'Column I or column M
        If UCase(Target) = "YES" Then Target.Offset(0, -1).ClearContents
    End If
End Sub
 
Not really no to be honest. If you do what you are asking you are going to be deleting your formulas so they arent going to work tomorrow. What is in A8 and how is that getting filled?
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Sorry hard to explain! that's fine if its deleted as each line is only used once, i have another VBA that runs to create a new line before this condition is met so an updated version will be added to the bottom. essentially its for a schedule each line is a task and once its marked as submitted the other VBA runs to generate a new line with the same task just one year later. as its in a table the formulas automatically get added to the new line so its ok if they are removed.
 
Upvote 0
See if this works. Test on a copy of your workbook first!

Code:
Private Sub Worksheet_Calculate()

Dim lr As Long, arr, arrCol, i As Long, j As Long, rng As Range

lr = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

arr = Range("A1:T" & lr)
arrCol = Array(11, 16, 17, 19, 20)

For i = LBound(arr) To UBound(arr)
    For j = LBound(arrCol) To UBound(arrCol)
        If LCase(arr(i, arrCol(j))) = "yes" Then
            If Not rng Is Nothing Then
                Set rng = Union(rng, Cells(i, arrCol(j) - 1))
            Else
                Set rng = Cells(i, arrCol(j) - 1)
            End If
        End If
    Next
Next

If Not rng Is Nothing Then rng.ClearContents

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Union(Columns(11), Columns(16), Columns(17), Columns(19), Columns(20))) Is Nothing Then
    Worksheet_Calculate
End If

End Sub
 
Upvote 0
Thanks Steve, having a slight issue, the code is freezing the whole document it ran once (and looks like it works from what i can see) but after the first run the document becomes unusable. it keeps displaying a run time error. the line that throws an error is
Code:
lr = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
 
Upvote 0
So the Worksheet isn't blank its running and clearing the values and not stopping searching, just keeps going.
 
Upvote 0
Oh ok. Try changing:

Code:
If Not Rng Is Nothing Then Rng.ClearContents

to

Code:
Application.EnableEvents = False
If Not Rng Is Nothing Then Rng.ClearContents
Application.EnableEvents = True
 
Upvote 0
@stevethefish thank you so much!! it looks to be working perfectly, have tested it with a few different dates! i have been looking for this answer for so long!!!
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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