IF formula with drop down list

IsmailA

New Member
Joined
Dec 14, 2023
Messages
3
Office Version
  1. 365
how can can i use IF function with the "data validation" drop down list in case of the condition was not met.
in the attached file, the condition is "B is blank", if met so "D8 must be blank", if not met "D8 will be chosen from a drop down list "M8:M38"
Trainees Scoring Sheet - Copy.xlsx
ABCDEFGHIJKLMNO
1Training Program
2Type of Training
3Date
4Location
5
6
7#Trainee NameAttendancePre-Post TestActivitiesOn-SiteTotal ScoreNoteAttendancePre-Post TestActivitiesOn-Site
81ManarAll26233584All000
92MagedNone201540NoneNone111
103MuradAll18153770222
114ZainAll20262369333
125ZumurrdaNone141016None444
136TamerAll0555
147KamalNoneNone666
158 777
169 888
1710 999
1811 101010
1912 111111
2013 121212
2114 131313
2215 141414
2316 151515
2417 161616
2518 171717
2619 181818
2720 191919
2821 202020
2922 212121
3023 222222
3124 232323
3225 242424
3326 252525
3427 262626
3528 272727
3629 282828
3730 292929
3831 303030
3932 31
4033 32
4134 33
4235 34
4336 35
4437 36
4538 37
4639 38
4740 39
4841 40
4942 
5043 
5144 
5245 
5346 
5447 
5548 
5649 
5750 
Initial Training
Cell Formulas
RangeFormula
G8:G57G8=IF(C8="","",(IF(C8="All",(SUM(D8:F8)),"None")))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G8:G57Cell Valuebetween 70 and 100textNO
G8:G57Cell Valuebetween 0 and 69textNO
G8:G57Cell Valuecontains "None"textNO
G8:G57Cellcontains a blank value textNO
Cells with Data Validation
CellAllowCriteria
C8:C57List=$L$8:$L$9
D8:E57Whole numberbetween 0 and 30
F8:F57Whole numberbetween 0 and 40
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
The following addresses the issue of the Validation List selecting either a blank, or from a list depending on whether column B is blank or not. However, it will still allow a number to be added if column B is blank - I think you will need a VBA solution for that. Depends how complicated you want your sheet to be?
Book1
ABCDEFGHIJKLMNO
1Training Program
2Type of Training
3Date
4Location
5
6
7#Trainee NameAttendancePre-Post TestActivitiesOn-SiteTotal ScoreNoteAttendancePre-Post TestActivitiesOn-Site
81ManarAll26233584All000
92MagedNone201540NoneNone111
103MuradAll18153770222
114ZainAll20262369333
125ZumurrdaNone141016None444
136TamerAll0555
147KamalNoneNone666
158 777
169 888
1710 999
1811 101010
1912 111111
2013 121212
2114 131313
2215 141414
2316 151515
2417 161616
2518 171717
2619 181818
2720 191919
2821 202020
2922 212121
3023 222222
3124 232323
3225 242424
3326 252525
3427 262626
3528 272727
3629 282828
3730 292929
3831 303030
3932 31
4033 32
4134 33
4235 34
4336 35
4437 36
4538 37
4639 38
4740 39
4841 40
4942 
5043 
5144 
5245 
5346 
5447 
5548 
5649 
5750 
Sheet1
Cell Formulas
RangeFormula
G8:G57G8=IF(C8="","",(IF(C8="All",(SUM(D8:F8)),"None")))
Cells with Data Validation
CellAllowCriteria
D8:D57List=IF($B8="",$P$8,$M$8:$M$38)
E8:E57List=IF($B8="",$P$8,$N$8:$N$38)
F8:F57List=IF($B8="",$P$8,$O$8:$O$48)
 
Upvote 0
If you wanted to be sure that a number can't be added in columns D:F if column B is blank, put this worksheet change code in the sheet code module of the Initial Training sheet. Right click the sheet tab name, select View Code & copy the code below to the window that appears on the right of screen. You'll need to save the file as either macro-enabled or binary format for it to work.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("D8:F57"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        If Cells(Target.Row, 2) = "" Then
            MsgBox "Cannot enter number if Trainee Name is blank"
            Target = ""
            Target.Select
        End If
    End If
    
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
 
Upvote 0
Solution
If you wanted to be sure that a number can't be added in columns D:F if column B is blank, put this worksheet change code in the sheet code module of the Initial Training sheet. Right click the sheet tab name, select View Code & copy the code below to the window that appears on the right of screen. You'll need to save the file as either macro-enabled or binary format for it to work.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("D8:F57"), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        If Cells(Target.Row, 2) = "" Then
            MsgBox "Cannot enter number if Trainee Name is blank"
            Target = ""
            Target.Select
        End If
    End If
   
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
Sorry, as a beginner I have a question. If I enable the macro, how can I be ensured that it will not work on the other excel files.
 
Upvote 0
Sorry, as a beginner I have a question. If I enable the macro, how can I be ensured that it will not work on the other excel files.
Not only will it not work on other Excel files, it won't even work on any other sheet within the same file.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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