Consulting

Results 1 to 5 of 5

Thread: Solved: The Dreaded #REF!

  1. #1
    VBAX Contributor CaptRon's Avatar
    Joined
    Mar 2007
    Location
    Austin, Texas
    Posts
    141
    Location

    Solved: The Dreaded #REF!

    I use this code to disable several tools/options to limit the actions available to the user. My initial aim was to keep the user from cutting a cell and pasting it elsewhere and thus creating a #REF! error in a dependant formula. I still haven't figured out how to disable the keyboard shortcut Ctrl+c.

    [vba]Sub EnableControls()
    'Called when workbook deactivated to restore full edit capability

    On Error Resume Next

    With Application
    With .CommandBars("Worksheet Menu Bar")
    .Controls("File").Controls("Save As...").Enabled = True
    .Controls("Edit").Controls("Cut").Enabled = True
    .Controls("Edit").Controls("Delete...").Enabled = True
    .Controls("Edit").Controls("Delete Sheet").Enabled = True
    .Controls("Insert").Controls("Cells...").Enabled = True
    .Controls("Insert").Controls("Rows").Enabled = True
    .Controls("Insert").Controls("Columns").Enabled = True
    .Controls("Format").Controls("Sheet").Enabled = True
    End With

    With .CommandBars("Ply")
    .Controls("Delete").Enabled = True
    .Controls("Rename").Enabled = True
    End With

    With .CommandBars("Standard")
    .Controls("Save As...").Enabled = True
    .Controls("Cut").Enabled = True
    .Controls("Delete").Enabled = True
    .Controls("Delete Sheet").Enabled = True
    .Controls("Cells").Enabled = True
    .Controls("Rows").Enabled = True
    .Controls("Columns").Enabled = True
    End With
    End With

    End Sub
    Sub DisableControls()
    'Called when workbook activated to limit user edit capability

    On Error Resume Next

    With Application
    With .CommandBars("Worksheet Menu Bar")
    .Controls("File").Controls("Save As...").Enabled = False
    .Controls("Edit").Controls("Cut").Enabled = False
    .Controls("Edit").Controls("Delete...").Enabled = False
    .Controls("Edit").Controls("Delete Sheet").Enabled = False
    .Controls("Insert").Controls("Cells...").Enabled = False
    .Controls("Insert").Controls("Rows").Enabled = False
    .Controls("Insert").Controls("Columns").Enabled = False
    .Controls("Format").Controls("Sheet").Enabled = False
    End With

    With .CommandBars("Ply")
    .Controls("Delete").Enabled = False
    .Controls("Rename").Enabled = False
    End With

    With Application.CommandBars("Standard")
    .Controls("Save As...").Enabled = False
    .Controls("Cut").Enabled = False
    .Controls("Delete").Enabled = False
    .Controls("Delete Sheet").Enabled = False
    .Controls("Cells").Enabled = False
    .Controls("Rows").Enabled = False
    .Controls("Columns").Enabled = False
    End With
    End With

    'For OAI staff and administrator
    If ThisWorkbook.Sheets("Start").Range("DF6").Value > 1 Then
    With Application
    .CommandBars("Worksheet Menu Bar").Controls("File") _
    .Controls("Save As...").Enabled = True
    .CommandBars("Standard").Controls("Save As...").Enabled = True
    End With
    End If

    End Sub[/vba]

    The problem now remains that the user can MOVE a cell to another by using the drag & drop method and this also creates #REF! in the formula containing the cell reference.

    Does anyone know how to disable moving a cell to another cell position?

    Anyone know how to disable Ctrl+c?

    Thanks for your help.

    Ron
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You've entered the twilight zone Cap. I use userforms to completly avoid this kind of problem......user never gets to touch the sheets.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by CaptRon
    ...Does anyone know how to disable moving a cell to another cell position?

    Anyone know how to disable Ctrl+c?

    Thanks for your help.

    Ron

    Hi Cap'

    I certainly agree w/Steve, if you can keep 'em off the sheet, that would seem best. If not...

    To just disable drag-and-drop, Application.CellDragAndDrop = False Of course the user can just turn it right back on... and I don't know the control name/number to disable.

    Mostly I thought to respond to the disabling of copy/paste including the shortcut key combo. Here's a link to a fairly recent thread - at post #4 I have the links to a kb entry by Ken Puhls as well as some updating done (if my memory serves). Anyways you could see if these help.

    http://www.vbaexpress.com/forum/showthread.php?t=23460

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=373

    http://www.vbaexpress.com/forum/showthread.php?t=19391

    Mark

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Ron,
    Can you not just assign it to another macro?
    [VBA]Sub test()
    MsgBox "Control C disabled"
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Contributor CaptRon's Avatar
    Joined
    Mar 2007
    Location
    Austin, Texas
    Posts
    141
    Location
    Thanks one an all for your assistance. I think I can manage with the information you've provided.

    Steve, I'm not sure I'm up to building a userform with well over 200 data entry fields. User has to be able to draw a diagram on the report as well. I've employed userforms occasionally in the past, usually to provide a means of access or navigation, but never the whole enchilada.

    I appreciate all your help.

    Ron
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •