How to create a data validation rule that includes a drop down menu and forbids the user from editing a cell if one other cell in that row is edited?

Eggy66

New Member
Joined
May 5, 2024
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Say I have this table:


Untitled2.png


How can I make it so that the user are only able to mark one column for each row while retaining the drop down menu?
Any help would be much appreciated!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Please try the following on a copy of your workbook:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("B:E"), Target) Is Nothing Then
       Application.EnableEvents = False
       Dim i As Long
       With Range(Cells(Target.Row, 2), Cells(Target.Row, 5))
           i = WorksheetFunction.CountIf(.Cells, "x")
           If i > 1 Then
               MsgBox "Only one category allowed per word"
               Target = ""
           End If
       End With
       Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Here is another variant. This just deletes the other cells in row without any other error checking:

During set up you just need to input the row and column numbers that are the top and bottom limits of the range.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
TargetAdd = Target.Address
Call ClearOtherCells(TargetAdd)
Application.EnableEvents = True
End Sub


Sub ClearOtherCells(TargetAddress As Variant)
Dim ColumnChanged As Integer
Dim RowChanged As Integer
Dim ColumnOffset As Integer
Dim i As Integer

RowChanged = Range(TargetAddress).Row
ColumnChanged = Range(TargetAddress).Column
' This ensures only B2:E5 are processed
If (RowChanged >= 2 And RowChanged <= 5 And ColumnChanged >= 2 And ColumnChanged <= 5) = False Then Exit Sub
'Loop for number of columns
For i = 2 To 5
ColumnOffset = i - ColumnChanged
      If ColumnOffset <> 0 Then
        Range(TargetAddress).Offset(0, ColumnOffset).ClearContents
        End If
 Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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