Making a cell mandatory to fill before being able to fill in another cell with a drop-down

thc_22

New Member
Joined
Sep 26, 2024
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hi, I have the following table:
Car NameColour
Car_021Red
Car_022Grey
Car_023Blue

Car name is a specific name. And colour is a drop down list. I'm trying to add a data validation to the colour column so that before a colour option can be selected the car name must not be empty. If they tried to fill in the colour column from the drop down list, then an error message should appear.

I've tried a formula such as isblank and selecting the drop down list cell. But it hasn't worked. I was wondering if anyone knew how to do this with data validation? Thanks.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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. Make a selection in the drop down.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column <> 2 Then Exit Sub
    Application.EnableEvents = False
    If Target.Offset(, -1) = "" Then
        MsgBox ("Please enter the car name in cell A" & Target.Row)
        Target.ClearContents
        Range("A" & Target.Row).Select
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
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. Make a selection in the drop down.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column <> 2 Then Exit Sub
    Application.EnableEvents = False
    If Target.Offset(, 2) = "" Then
        MsgBox ("Please enter the car name in cell A" & Target.Row)
        Target.ClearContents
        Range("A" & Target.Row).Select
    End If
    Application.EnableEvents = True
End Sub
Hi mumps,
Thanks for adding the macro code. I'm trying to do it without VBA.

Sorry, I should have clarified earlier
 
Upvote 0
I think you may need a macro to do what you want. Please note that I have modified this line of code:
VBA Code:
If Target.Offset(, 2) = "" Then
to
VBA Code:
If Target.Offset(, -1) = "" Then
 
Upvote 0

Forum statistics

Threads
1,222,093
Messages
6,163,871
Members
451,863
Latest member
Bernie Galve

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