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?
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,343
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"
 

p45cal

Well-known Member
Joined
Nov 10, 2009
Messages
4,763
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?
 

marokay

New Member
Joined
Jul 19, 2010
Messages
5
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)
 

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,343
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
 

marokay

New Member
Joined
Jul 19, 2010
Messages
5
I do not understand how the - "Already Done!" will come in automatically after the cell was deleted ?
 

Watch MrExcel Video

Forum statistics

Threads
1,108,450
Messages
5,523,065
Members
409,495
Latest member
bkahn

This Week's Hot Topics

Top