Macro run when cell in column changes to "done"

B-Man

Board Regular
Joined
Dec 29, 2012
Messages
183
Office Version
  1. 2019
Platform
  1. Windows
I want to create a macro so whenever a cell in column E changes to "Done" it runs the macro.

currently I have this so whenever a cell changes in column E it runs so that caused a never ending loop then crashes...

am I able to set this up to only run when it changes to "done"
the problem I see is it filters the data so the cells change again.... causing it to run again...

Any ideas?


VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("E:E")) Is Nothing Then



     ActiveWorkbook.Worksheets("Notes").ListObjects("Table2").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Notes").ListObjects("Table2").Sort.SortFields.Add( _
        Range("Table2[Status]"), xlSortOnFontColor, xlDescending, , xlSortNormal). _
        SortOnValue.Color = RGB(208, 206, 206)
    With ActiveWorkbook.Worksheets("Notes").ListObjects("Table2").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With



End If

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You can check for "Done" as follows:

VBA Code:
If Target.Value = "Done" Then


I'd also suggest you use

VBA Code:
Application.EnableEvents = False
.
.
.
Application.EnableEvents = True

at the start and end of your macro. That will prevent it from calling the event routine when the trigger happens from within the event routine.
 
Upvote 0
Solution
Cheers worked a treat.
I did have an issue

With this
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
It should have been
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
As it was only working on selection of cell not change explains why it was only working a small amount
Also added OR "done"
VBA Code:
If Target.Value = "Done" or "done" Then
 
Upvote 0
Good catch on changing it to Worksheet_Change. But I think you need to change the If to

VBA Code:
If Target.Value = "Done" or Target.Value = "done" Then

or

VBA Code:
If LCase(Target.Value) = "done" Then


The "or" in a VBA comparison requires a full condition.
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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