Restrict values in 1 column

kathleenfarber

New Member
Joined
Sep 26, 2016
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to restrict values in column D if column G has an entry of 1 and vice versa. I don't think Data Validation will work. Any ideas? Example is if they choose full service in Units A they are unable to choose Units B and vice versa. Any help appreciated.

ANNUAL FEEUNITS ACOSTANNUAL FEEUNITS BCOST
NSCLC$100.00( auto computes )$60.00(auto computes)
Late IO$500.00( auto computes )$500.00( auto computes )
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D:D,G:G")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Select Case Target.Column
        Case Is = 4
            If Range("G" & Target.Row) <> "" Then
                If MsgBox("You have already chosen Units B." & Chr(10) & "If you want to choose Units A, you will have to delete Units B." & Chr(10) & "Do you want to delete Units B?", vbYesNo) = vbYes Then
                    Range("G" & Target.Row).ClearContents
                Else
                    Target.ClearContents
                End If
            End If
        Case Is = 7
            If Range("D" & Target.Row) <> "" Then
                If MsgBox("You have already chosen Units A." & Chr(10) & "If you want to choose Units B, you will have to delete Units A." & Chr(10) & "Do you want to delete Units A?", vbYesNo) = vbYes Then
                    Range("D" & Target.Row).ClearContents
                Else
                    Target.ClearContents
                End If
            End If
    End Select
    Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
@mumps would you be willing to help me merge these two macro's? I'm very new to this. Slowly learning!

The one you provided works perfectly! I just need to combine the following:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D5:D29,G5:G29")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Select Case Target.Column
        Case Is = 4
            If Range("G" & Target.Row) <> "" Then
                If MsgBox("You have already chosen units under LSIO COMBINED." & Chr(10) & "If you want to choose units under FULL SERVICE, you will have to delete the LSIO COMBINED." & Chr(10) & "Do you want to delete the LSIO COMBINED units?", vbYesNo) = vbYes Then
                    Range("G" & Target.Row).ClearContents
                Else
                    Target.ClearContents
                End If
            End If
        Case Is = 7
            If Range("D" & Target.Row) <> "" Then
                If MsgBox("You have already chosen units under FULL SERVICE." & Chr(10) & "If you want to choose units under LSIO COMBINED, you will have to delete units under FULL SERVICE." & Chr(10) & "Do you want to delete units under FULL SERVICE?", vbYesNo) = vbYes Then
                    Range("D" & Target.Row).ClearContents
                Else
                    Target.ClearContents
                End If
            End If
    End Select
    Application.EnableEvents = True
End Sub


Sub MainClearcells()
Range("D5", "D29").ClearContents
Range("G5", "G28").ClearContents
Range("J5", "J29").ClearContents
End Sub
 
Upvote 0
VBA Code:
Range("D5", "D29").ClearContents
Range("G5", "G28").ClearContents
Range("J5", "J29").ClearContents
When do you want to clear these cells? At what stage in the process do you want to clear these ranges?
 
Upvote 0
I thought you wanted to merge the two macros you posted. The Worksheet_Change macro you posted does exactly the same thing as the macro I suggested so I'm not sure how you want to combine them. As far as I can see, comparing the two, there is no need to merge them because they basically do the same thing. Please clarify in detail what you would like to do.
 
Upvote 0
I see what you are saying now! I have a button on a different sheet to clear a different chart. Thought I could do the same on this sheet. The original macro you helped with is more than enough. It's been a day with this file LOL just want it done. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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