+ Reply to Thread
Results 1 to 2 of 2

Disable a cell if another is filled

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-27-2010
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    115

    Disable a cell if another is filled

    Hi guys,

    I need a simple help. i'm creating a spreadsheet but i can't get past an issue.
    I need to disable a certain cell if another cell is filled, meaning:

    If cell A1 is filled then cell B1 is blocked, so no data can be filled.
    If cell B1 is filled then cell A1 is blocked, so no data can be filled.

    If i delete the data in any cell (A1 or B1) then both cells become enabled.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    04-02-2012
    Location
    NY
    MS-Off Ver
    Excel 2003 / 2007
    Posts
    7

    Re: Disable a cell if another is filled

    Try the below code, I believe it is what you're looking for, or at least it will get you started. Play around with it before actually applying it.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        'set your criteria here
        If Target = Me.Range("A1") Then
            If (Trim(Me.Range("B1")) <> "") Then
                UndoEvent
            End If
        ElseIf Target = Me.Range("B1") Then
            If (Trim(Me.Range("A1")) <> "") Then
                UndoEvent
            End If
        End If
    End Sub
    
    Private Sub UndoEvent()
            Application.EnableEvents = False
            Application.Undo
            Application.EnableEvents = True
            MsgBox "YOU CAN'T DO THAT!!!"
    End Sub
    Hope this helps.

    Wes

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1