Hello,
I'm trying to insert a return value based on the value from a drop-down list using WorksheetFunction.Xlookup... within an existing Worksheet Change event.
Scenario:
What I'm trying to do now is automatically set the cell value based on the Students active Period… without breaking the Data Validation (drop-down) list.
Tried:
If I run the following code by itself, it will return and enter the correct value into the cell.
However, when I try to use this code in the Worksheet Change code (below), it returns the following error:
My complete Worksheet Change code is:
Any help would be greatly appreciated.
Thank you,
Microsoft Office 365 (latest update)
I'm trying to insert a return value based on the value from a drop-down list using WorksheetFunction.Xlookup... within an existing Worksheet Change event.
Scenario:
- I select a Student Name from a drop-down list.
- This triggers a Worksheet Change event to create the drop-down list values (Year.Quarters) for the given Student (Period column). This works just fine.
- I then need to select the active Period (Year.Quarter) from this new list of values. EX: 3.2
What I'm trying to do now is automatically set the cell value based on the Students active Period… without breaking the Data Validation (drop-down) list.
Tried:
If I run the following code by itself, it will return and enter the correct value into the cell.
VBA Code:
Sub WIP_Set_Active_Period()
Range("t_Period_Active[Period]").Value = _
WorksheetFunction.XLookup(Range("t_Period_Active[Name]"), _
Range("t_Students[Name]"), Range("t_Students[Period]"))
End Sub
However, when I try to use this code in the Worksheet Change code (below), it returns the following error:
My complete Worksheet Change code is:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
'If Name is changed
If Not Intersect(Target, Range("t_Period_Active[Name]")) Is Nothing Then
'Refresh Period List
wsLists.Range("l_PlannerPeriod_DV").Calculate
'Set Active Period
' Range("t_Period_Active[Period]").Value = WorksheetFunction.XLookup(Range("t_Period_Active[Name]"), Range("t_Students[Name]"), Range("t_Students[Period]"))
'If Period is changed
ElseIf Not Intersect(Target, Range("t_Period_Active[Period]")) Is Nothing Then
wsLists.Range("c_Planner_DateList").Calculate
'Calculate Table Data
wsPlanner.Calculate
Application.EnableEvents = True
End Sub
Any help would be greatly appreciated.
Thank you,
Microsoft Office 365 (latest update)