Hello,
I've got a macro working that creates a Data Validation drop-down list. I duplicated it to repeat the process for a list of three dates.
However, no matter what I do, they never make it into the Data Validation Source field in the format they show in the VBE.
VBE Shows:
DV Source:
I'm using the following code to build the dates based on the Start Date. Days are then added in a loop using three values in an array (0,7,14).
NOTE:
The other problem is that it's not seen as a date in Excel (E7).
I'm currently using a formula on another sheet to extract those three dates. Then I'm using the Named Range for those three dates for the DV List. Sample data shown at the bottom.
However, I would prefer to use a vba-based solution if possible.
Any help with getting the DV Source field populated with the three dates in yyyy-mm-dd format would be greatly appreciated. From there, I suspect Excel will properly detect it as a Date (ISNUMBER) format.
Create Date Drop-Down List:
Sample Data for VBA-based Solution:
Current Formula-based Solution:
Excel is gonna crash trying to create the MiniSheet... I'll add it below shortly...
I've got a macro working that creates a Data Validation drop-down list. I duplicated it to repeat the process for a list of three dates.
However, no matter what I do, they never make it into the Data Validation Source field in the format they show in the VBE.
VBE Shows:
DV Source:
I'm using the following code to build the dates based on the Start Date. Days are then added in a loop using three values in an array (0,7,14).
NOTE:
- StartDate + Days is just adding the three dates into a String.
- StartDate + Days & Format Date ATTEMPT is me attempting to force the format output of the dates... to no avail.
The other problem is that it's not seen as a date in Excel (E7).
I'm currently using a formula on another sheet to extract those three dates. Then I'm using the Named Range for those three dates for the DV List. Sample data shown at the bottom.
However, I would prefer to use a vba-based solution if possible.
Any help with getting the DV Source field populated with the three dates in yyyy-mm-dd format would be greatly appreciated. From there, I suspect Excel will properly detect it as a Date (ISNUMBER) format.
Create Date Drop-Down List:
VBA Code:
Sub Planner_List_Dates()
'Declarations
Dim StartDate As Date, i As Integer, sDate As String
Dim DateList As String: DateList = "" 'Date List
'Get Start Date
StartDate = Range("A2")
' StartDate = Format(Range("A2"), "yyyy-mm-dd")
'Days to Add to StartDate in Loop
Dim indexArr As Variant
indexArr = Array(0, 7, 14)
'Build Drop-Down List Values
For i = LBound(indexArr) To UBound(indexArr)
'StartDate + Days
DateList = DateList & StartDate + indexArr(i) & ","
'StartDate + Days & Format Date ATTEMPT
'sDate = Format(StartDate + indexArr(i), "yyyy-mm-dd")
'DateList = DateList & sDate & ","
Next i
'What's happening here?
DateList = Mid(DateList, 1, Len(DateList) - 1)
'Add Drop-Down List v1
With Range("E2").Validation
.Delete
.Add _
Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Formula1:=DateList
End With
End Sub
Sample Data for VBA-based Solution:
VBA Testing.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | Start Date | Planner Dates | DV List | + Days | |||||
2 | 2025-01-06 | 2025-01-06 | 1/6/2025 | 0 | |||||
3 | 2025-01-13 | 7 | |||||||
4 | 2025-01-20 | 14 | |||||||
5 | |||||||||
6 | Date? | Date? | Date? | ||||||
7 | TRUE | TRUE | FALSE | ||||||
8 | TRUE | ||||||||
9 | TRUE | ||||||||
Dates_DV |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C2:C4 | C2 | =$A$2+$G2 |
A7,E7 | A7 | =ISNUMBER(A2) |
C7:C9 | C7 | =ISNUMBER($C2) |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
E2 | List | 1/6/2025,1/6/2025,1/6/2025 |
Current Formula-based Solution:
Excel is gonna crash trying to create the MiniSheet... I'll add it below shortly...