hiding formulas

ehsas69

Board Regular
Joined
Jan 10, 2004
Messages
221
I need help for the following two question

1)how i can hide the formula available in the worksheet from users.

2) hoq i can protect the the formula from changing.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
The answer to both is protecting the sheet.

Select the cells you do *not* want the users to be able to change. Go to Format\Cells\Protection tab and check the box next to "Locked" so that it is selected.

For the cells with formulas, select both "Locked" and "Hidden."

Then protect the sheet.

The users will be unable to change the cells you locked, and those cells that are locked with formulas will not have the formula visible in the formula bar if they are selected.
 
Upvote 0
Thanks it works.

How I can prevent the formula's from changing when the worksheet is unprotected.
 
Upvote 0
When it's unprotected? You can't, not really.

Though I suppose you could *technically* do it if you used a macro to check for changes to the sheet, detect if the changed cell had a formula in it, display a message telling the user they can't change it, then return the formula to the cell...

Which really may be more trouble than it's worth; depending on what you're doing.
 
Upvote 0
Right...

This seems to be working for me, but I doubt I've worked all the kinks out. There are 2 events used for this--the first one will capture the value of the cell when it is selected, the other will return the captured value (that is, the formula) to the cell if it is changed:

Code:
Dim ChkFormula As Boolean, PrevFormula As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'if sheet is not protected
If ActiveSheet.ProtectionMode = False Then
    
    'check if selected cell contains formula
    ChkFormula = Target.HasFormula
    
    'if selected cell contains formula, save formula to variable
    If ChkFormula = True Then PrevFormula = Target.Formula
End If

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

'if sheet is not protected
If ActiveSheet.ProtectionMode = False Then
    
    'if changed cell contains formula
    If ChkFormula = True Then
        Application.EnableEvents = False
        
        'display message box
        MsgBox "This cell contains a formula. " _
        & vbCrLf & "Changing this cell is not allowed.", _
        vbExclamation, "Formula Found"
        
        'replace formula in changed cell
        Target.Formula = PrevFormula
        
        Application.EnableEvents = True
    End If
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,600
Messages
6,056,200
Members
444,850
Latest member
dancasta7

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