打开VBA编辑器,在你要添加下拉式选单的工作表模块中编写以下代码:
Private
Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim DateList As Range
Dim ValidationList As String
Set DateList = Range("DateList")
ValidationList = Join(Application.Transpose(DateList), ",")
If Not Intersect(Target, Range("DateCell")) Is Nothing Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, Formula1:=ValidationList
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
End Sub
上面的代码创建了一个名为"DateList"的日期列表,并在"DateCell"单元格处添加了下拉式选单。你可以根据需要修改这些单元格和范围名称。
接下来,在工作表中创建日期列表。可以在单独的工作表中创建一个名为"DateList"的列表,在列表中输入所有可用的日期。
最后,在需要添加下拉式日期选单的单元格中输入日期,选定单元格后,下拉式日期选单将出现并提供可用日期列表。
希望这些步骤能够帮到你。
- 592
-
HackerNews什么值得看
Python