Action to be carried out only once in VB

marokay

New Member
Joined
Jul 19, 2010
Messages
5
Hello,
I want the action Display in this code:

Code:
Private Sub Worksheet_Calculate()
If Range("I4").Value = "1" And Range("O9").Value = "PLACED" Then Range("O9").ClearContents
If Range("I4").Value = "1" And Range("O11").Value = "PLACED" Then Range("O11").ClearContents
End Sub

Take place only once!
In the case that the conditions are in place it will trigger the deletion of the Q9 or Q11 but if these conditions will come back again he does not erase the cells ...
Is it possible?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
well you need a third condition then and it should be quite permanent.
option 1. reserve a cell somewhere (eventually hidden and locked) to fill in the remarks (as some value) that this has already been done.
option 2. instead of a cell you can create and use a "Custom document property"
 
Upvote 0
In the case that the conditions are in place it will trigger the deletion of the Q9 or Q11 but if these conditions will come back again he does not erase the cells ...
Do you want the two cells to be treated independently? SFor example, if only one of the cells is cleared, do you still want the other cell to be checked?
 
Upvote 0
well you need a third condition then and it should be quite permanent.
option 1. reserve a cell somewhere (eventually hidden and locked) to fill in the remarks (as some value) that this has already been done.
option 2. instead of a cell you can create and use a "Custom document property"

How can I do the first option? (i am a bginer in VB)
 
Upvote 0
Code:
Sheets("Sheet1").Range("A1").Value = "Already Done!"
....
Code:
If NOT Sheets("Sheet1").Range("A1").Value = "Already Done!" Then
            If Range("I4").Value = "1" And Range("O9").Value = "PLACED" Then Range("O9").ClearContents
            If Range("I4").Value = "1" And Range("O11").Value = "PLACED" Then Range("O11").ClearContents
End If
or
Code:
If Sheets("Sheet1").Range("A1").Value = "Already Done!" Then Exit Sub
If Range("I4").Value = "1" And Range("O9").Value = "PLACED" Then Range("O9").ClearContents
If Range("I4").Value = "1" And Range("O11").Value = "PLACED" Then Range("O11").ClearContents
 
Upvote 0
I do not understand how the - "Already Done!" will come in automatically after the cell was deleted ?
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

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