To protect formulas in cells:
When we create a
 spreadsheet, most of us need to use formulas of some sort. Sometimes, 
however, you might not want other users to tamper/delete/overtype any 
formulas you included on your spreadsheet. The easy way of barring 
people from playing with your formulas is to protect your formulas with 
vba.
 You can use the Worksheet Change function to protect the formulas in the cells.
Example code :    Private Sub Worksheet_Change(ByVal Target As Range)
 If Target.Address = "$G$21" Then
 Target.Formula = "=E21*F21"
 ElseIf Target.Address = "$G$22" Then
 Target.Formula = "=E22*F22"
 ElseIf Target.Address = "$G$23" Then
 Target.Formula = "=E23*F23"
End If
End Sub
or
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("K11")) Is Nothing Then
 Target.Formula = "=G11*H11"
 ElseIf Not Intersect(Target, Range("k12")) Is Nothing Then
 Target.Formula = "=G12*H12"
 ElseIf Not Intersect(Target, Range("k13")) Is Nothing Then
 Target.Formula = "=G13*H13"
 ElseIf Not Intersect(Target, Range("k14")) Is Nothing Then
 Target.Formula = "=G14*H14"
 ElseIf Not Intersect(Target, Range("k15")) Is Nothing Then
 Target.Formula = "=G15*H15"
 ElseIf Not Intersect(Target, Range("k16")) Is Nothing Then
 Target.Formula = "=G16*H16"
End If
End Sub
 Home Home
 Excel VBA Examples Excel VBA Examples- Advanced Filter With Drop Down Lists
- Assigning Macro To Short-Cut Key
- Warning If A Column Has Duplicate Values
- The Workbook Backup
- Calendar Control
- Calling Image From Other Sheet With Combobox
- Changing Background Color With Scrollbar
- Cutting - Pasting To Other Sheet
- Excel Chronometer
- Highlight Duplicate Records
- Hide & Unhide Columns With Combobox
- Excel Combobox In Alphabetic Order
- Excel Combobox Unique Values
- Excel Compare Columns
- Excel Vba Context (Right-Click) Menu
- Convert Numbers To English Words
- Convert Excel Data To Html Table
- Copy & Paste Macro
- Copying Excel To Word
- Listbox Copying Filtered Data
 
 Excel VBA Userform Examples Excel VBA Userform Examples
-   How To Do How To Do
-   Software Software
- Entertainment
 
 
No comments:
Post a Comment