Block referencing another cell

Excel-Probie

New Member
Joined
Nov 17, 2009
Messages
33
Another question as I am not up on macros. I want to block users from simply entering into a cell "C86" a formula pointing to cell "C84". They will need enter a formula as they are adding up numbers from the general ledger into cell "C86". I just want to ensure that they are looking at the general ledger and not taking a short cut.

THanks again
 

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.
If you aren't up on macros, controlling user entry to that degree will be a headache.
You could put something like this in a Worksheet_Change event.

Code:
If Target.Address = "$C$86" Then
    If Target.HasFormula Then
        Application.EnableEvents = False
        Target.ClearContents
        Application.EnableEvents = True
    End If
End If
(BTW, if it works, whats bad about shortcuts)
 
Upvote 0
Mike, I don't think your code checks to see if the formula entered into C86 references C84. The following should, though:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C86")) Is Nothing Then
    If InStr(1, Range("C86").Formula, "C84") > 0 Then
        MsgBox "You cannot reference cell C84 from this cell. Use the GL data, dummy!"
        Target.Clear
    End If
End If
End Sub
 
Upvote 0
Below is the changes I made to the Macro and it is working. Is there a more efficient way to do this.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C86:K86")) Is Nothing Then
If InStr(1, Range("C86").Formula, "C84") > 0 Then
MsgBox "You cannot reference cell C84 from this cell. Please use the information in the General Ledger!"
Target.Clear
End If
If InStr(1, Range("H86").Formula, "H84") > 0 Then
MsgBox "You cannot reference cell H84 from this cell. Please use the information in the General Ledger!"
Target.Clear
End If
If InStr(1, Range("J86").Formula, "J84") > 0 Then
MsgBox "You cannot reference cell J84 from this cell. Please use the information in the General Ledger!"
Target.Clear
End If
If InStr(1, Range("K86").Formula, "K84") > 0 Then
MsgBox "You cannot reference cell K84 from this cell. Please use the information in the General Ledger!"
Target.Clear
End If
End If
End Sub


Thanks
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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