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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,855
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
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,855
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
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 ?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,714
Messages
5,833,276
Members
430,201
Latest member
Deepakpilla36

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
Top