Can formula be removed by Excel

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
1,226
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
Can formula's in the cells be removed by Excel program/functions?

In Worksheet5, C2:C48 contains numeric values generated thr' formula =D2:D48.
Ex:
C2=D2

At a particular time, to remove formulas from C2:C48; I select, copy, paste special, values, Ok, Enter.

But can it be done by say putting a number 1 in C1 or by any other method.

This worksheet contains only these 2 columns.
Thanx in adv
 
2. In the ws1 (as referred to in post #24) module try this code
Rich (BB code):
Private Sub Worksheet_Calculate()
  If Range("C2").HasFormula Then
    If Range("C1").Value <= Now Then
      Application.EnableEvents = False
      With Range("C2:C48")
        .Value = .Value
      End With
      Application.EnableEvents = True
    End If
  End If
End Sub
[/QUOTE]

Peter,

Your above code WORKS FINE.

IF C1<=now, code gets triggered & formulas are REMOVED from C2:C48

Up to this, it’s quite fine & okay.

I require “EXTENSION” to this code…..

1. IF B1<=now, the formula should COME BACK in C2:C48

Please note here: C1 IS ALWAYS < B1

The formula in C2:C48 is

C2=D2
C3=D3
&
so on…
C48=D48

I am & would always remain thankful for your earlier & this help.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I'm not sure I understand how the "extension" should interact with the original so test this with caution.
If this is not it you will need to spell out in more detail and give examples of what is in B1 & C1 and what actions should happen in those circumstances.

Code:
Private Sub Worksheet_Calculate()
  If Range("C2").HasFormula Then
    If Range("C1").Value <= Now Then
      Application.EnableEvents = False
      With Range("C2:C48")
        .Value = .Value
      End With
      Application.EnableEvents = True
    End If
  ElseIf Range("B1").Value <= Now Then
    Application.EnableEvents = False
    Range("C2:C48").FormulaR1C1 = "=RC[1]"
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0
I'm not sure I understand how the "extension" should interact with the original so test this with caution.
If this is not it you will need to spell out in more detail and give examples of what is in B1 & C1 and what actions should happen in those circumstances.

EXTENSION: I need further modification in the existing code to achieve desired result.

C1=time value punched
B1= time value punched BUT always > C1

When C1<=now formulas get REMOVED from C2:C48

NOW I also need

IF B1<=now, the formula should COME BACK in C2:C48

This means C2:C48 which are currently values only would contain formulas only

C2=D2
C3=D3
&
so on…
C48=D48
 
Last edited by a moderator:
Upvote 0
When C1<=now formulas get REMOVED from C2:C48

IF B1<=now, the formula should COME BACK in C2:C48
Still not clear. What if B1 and C1 are both < Now? One of the above says to remove formulas, the other says to put them back. Which one wins and why?

As I said before, you haven't explained the interaction of the two circumstances ..

.. spell out in more detail and give examples of what is in B1 & C1 and what actions should happen in those circumstances.
 
Upvote 0
C1 & B1=time values

Always, C1<b1<b1
is less than B1
What if B1 and C1 are both < Now? B1 wins i.e. C2:C48 must contain formulas.

I will try to explain you practically:

C1=9:30:00AM 10/09/2018
B1=3:30:00PM 10/09/2018

now= 9:17:00AM 10/09/2018

As soon as now= 9:30:00AM 10/09/2018
Formulas from C2:C48 gets REMOVED. (Your code works fine up to this)

NOW

As soon as now= 3:30:00PM 10/09/2018
Formulas MUST COME BACK in C2:C48

REVISED code needed for this</b1<b1
 
Last edited:
Upvote 0
Try
Code:
Private Sub Worksheet_Calculate()
  If Range("B1").Value <= Now Then
    If Not Range("C2").HasFormula Then
      Application.EnableEvents = False
      Range("C2:C48").FormulaR1C1 = "=RC[1]"
      Application.EnableEvents = True
    End If
  ElseIf Range("C1").Value <= Now Then
    If Range("C2").HasFormula Then
      Application.EnableEvents = False
      With Range("C2:C48")
        .Value = .Value
      End With
      Application.EnableEvents = True
    End If
  End If
End Sub
 
Upvote 0
I'll try this code & report back the outcome tomorrow positively. Meanwhile Thanks a lot to you Sir
 
Upvote 0
Peter

Your Code WORKS. Many Thanks for this help rendered.

Please REVISE this code for a different formula to get back …..

Till now:
When B1<=now, code gets the formula back in C2:C48; the formula is
C2=D2
&
so on..till
C48=D48

REVISE
C2=IF((F2-I2)=0,0,((G2-J2)/(F2-I2)))
&
so on..till
C48=D48
 
Upvote 0
Please REVISE this code for a different formula to get back …..

REVISE
C2=IF((F2-I2)=0,0,((G2-J2)/(F2-I2)))
&
so on..till
C48
Is making this replacement in the code what you mean?
Rich (BB code):
Range("C2:C48").FormulaR1C1 = "=RC[1]"
Range("C2:C48").Formula = "=IF((F2-I2)=0,0,((G2-J2)/(F2-I2)))"
 
Last edited:
Upvote 0
Probably YES. I'll try this & report back the outcome tomorrow. Many thanks Peter once again.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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