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
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,920
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)
 

mvptomlinson

Well-known Member
Joined
Mar 10, 2008
Messages
2,638
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
 

Excel-Probie

New Member
Joined
Nov 17, 2009
Messages
33

ADVERTISEMENT

One last question on this issue, can I expand the macro to cover C86-K86
 

Excel-Probie

New Member
Joined
Nov 17, 2009
Messages
33
Does anyone know how I would change the macro to cover a range of cells C86 thru K86

Thanks
 

Excel-Probie

New Member
Joined
Nov 17, 2009
Messages
33
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,514
Messages
5,602,087
Members
414,501
Latest member
mdhaumyu

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