Conditional drop down list using vba

Wishmaster89

Board Regular
Joined
Jan 10, 2022
Messages
77
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
  2. MacOS
Hi Everyone

I have a conditional drop down list where a user can choose a course and a pathway which works fine.
The problem is one of the courses (IT) has an additional drop down list (column c), the problem is when the course in the first column is changed ( changed to Maths for example) column c is not clearing.

This is the VBA code i have that clears column B if column A changes.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, Range("A4:B18")) Is Nothing Then Target.Offset(columnoffset:=1).ClearContents
Application.EnableEvents = True
End Sub

drop down list offset example.xlsm
ABC
2CoursePathwayIf course is IT choose additional pathway
3Pathway Selection
4ITAccess databaseVBA
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Course selection
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B4:C18Expression=ISBLANK(XEL4)textNO
A4:C18Expression=ISBLANK(A4)textNO
A4:C18Expression=ISBLANK(A4)textNO
A4:C4Expression=ISBLANK(A4)textNO
A4:C4Expression=ISBLANKtextNO
A4:A18Expression=ISBLANK(XEJ4)textNO
Cells with Data Validation
CellAllowCriteria
A4:A18List=CourseList!$B$1:$E$1
B4:B18List=OFFSET(CourseList!$B$1,1,MATCH(A4,CourseList!$B$1:$E$1,0)-1,5,)
C4List=IF(C4="",OFFSET(CourseList!$M$1,1,MATCH(A4,CourseList!$M$1:$M$1,0)-1,5,),INDIRECT("FakeRange"))
C5:C18List=IF(A5<>"IT","",OFFSET(CourseList!$M$1,1,MATCH(A5,CourseList!$M$1:$M$1,0)-1,5,))
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Application.EnableEvents = False
  If Not Intersect(Target, Range("A4:B18")) Is Nothing Then
    With Target.Offset(0, 1)
      If Target.Column = 1 Then .Resize(1, 2).ClearContents Else .ClearContents
    End With
  End If
  Application.EnableEvents = True
End Sub
 
Upvote 1
Try this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Application.EnableEvents = False
  If Not Intersect(Target, Range("A4:B18")) Is Nothing Then
    With Target.Offset(0, 1)
      If Target.Column = 1 Then .Resize(1, 2).ClearContents Else .ClearContents
    End With
  End If
  Application.EnableEvents = True
End Sub

Thank you that does work but i forgot to add something in.
 
Upvote 0
I am trying to adapt the code given above to this spreadsheet but for some reason if a value in column N is changed the value in column P does not delete.
(Note, only "Insurance Practitioner Level 3" in col O and any of the options in O will trigger a value needed in P.

offset example 2 for forum.xlsm
ABCDEFGHIJKLMNOPQRS
5Employer:
6Planned Start Month:
7Apprentice Details:Employer Details: Programme Details:
8Apprentice ForenameApprentice SurnameStart Date in Role (mm/yyyy)Contract TypeWork EmailContact NumberApprentice works 30 hours +Annual Leave Dates (in the next month)Line Manager NameLine Manager EmailLine Manager Contact NumberEmployer office Digital Account Cohort ReferenceApprenticeship Standard & LevelProfessional QualificationIf Insurance Practitioner Level 3:First Workbook/Material to Order (if applicable)Further unit selection agreed? (Yes/No)If yes, please state here
9Pathway Selection
10Financial Services Administrator Level 3CII: RO1
11Insurance Practitioner Level 3Cert CILA: Certificate in Claims HandlingClaims Handler / Loss Adjuster
12Insurance Practitioner Level 3Cert CIIAssistant Underwriter
13Insurance Practitioner Level 3Cert CILA: Certificate in Claims HandlingClaims Handler / Loss Adjuster
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Apprentice(s) Details
Cells with Conditional Formatting
CellConditionCell FormatStop If True
O10:P29Expression=ISBLANK(O10) = FALSEtextNO
O10:P29Expression=ISBLANK(XFA10)textNO
O10:P29Expression=ISBLANK(XFA10)textNO
O10:P29Expression=ISBLANK(XFA9)textNO
N10:N29Expression=ISBLANK(N10) = FALSEtextNO
N10:N29Expression=ISBLANK(XEZ10)textNO
N11Expression=ISBLANK(XEZ11)textNO
A10:B29Expression=ISBLANK(A10)textNO
I10:M11,I12:N29Expression=ISBLANK(XEU10)textNO
A10:G29Expression=ISBLANK(A10)textNO
A29:G29Expression=ISBLANK(A29)textNO
A29:G29Expression=ISBLANK(A29)textNO
A25:G28Expression=ISBLANK(A25)textNO
A25:G28Expression=ISBLANK(A25)textNO
A24:G24Expression=ISBLANK(A24)textNO
A24:G24Expression=ISBLANK(A24)textNO
T10:XFD29,A10:G23,I10:Q29Expression=ISBLANK(A10)textNO
T10:XFD29,A10:G23,I10:Q29Expression=ISBLANK(A10)textNO
T10:XFD10,A10:G10,I10:M10,N11,O10:Q10,O10:P29Expression=ISBLANK(A10)textNO
T10:XFD10,A10:G10,I10:M10,N11,O10:Q10,O10:P29Expression=ISBLANKtextNO
N11Expression=ISBLANK(XEZ10)textNO
Q10:Q29Expression=ISBLANK(A10)textNO
O10:P29Expression=ISBLANK(XFB10)textNO
Cells with Data Validation
CellAllowCriteria
D10:D29List=#REF!$A$2:$A$5
G10:G29List=#REF!$I$2:$I$3
N10:N29List=Lists2!$B$1:$X$1
O10:O29List=OFFSET(Lists2!$A$1,1,MATCH(N10,Lists2!$A$1:$W$1,0)-1,4,)
P10:P29List=OFFSET(Lists2!$AB$1,1,MATCH(O10,Lists2!$AB$1:$AD$1,0)-1,2,)
 
Upvote 0

Forum statistics

Threads
1,215,247
Messages
6,123,853
Members
449,129
Latest member
krishnamadison

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