Hide formula in bar and calculate from macro

sujittalukde

Well-known Member
Joined
Jun 2, 2007
Messages
520
I am using the following recorded macro
Code:
Sub Macro4()

'

'
    ActiveSheet.Unprotect Password:=""
    ActiveCell.FormulaR1C1 = "=R[-2]C+R[-1]C"
    Range("A4").Select
    ActiveSheet.Protect Password:=""
End Sub

When I am deleting the formula at A3 and then running the macro, the formula again appears on the cell A3.
Also it refilects 0 (Zero) on cell A3 if A2 and a3 doesnat contain values.

Can this be modified in such a way that:
1. It will not display the formula on the formula bar
2. Cell A3 will be blank (instead of 0 - Zero) if A1 and A2 is blank.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
Maybe something like this?

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Test()
    ActiveSheet.Unprotect
    ActiveCell.FormulaR1C1 = "=IF(COUNT(R[-2]C:R[-1]C)=0,"""",R[-2]C+R[-1]C)"
    ActiveCell.Locked = <SPAN style="color:#00007F">True</SPAN>
    Selection.FormulaHidden = <SPAN style="color:#00007F">True</SPAN>
    ActiveSheet.Protect
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,190,911
Messages
5,983,525
Members
439,848
Latest member
timmyo

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