gpt4 book ai didi

Excel VBA 下拉列表,默认值

转载 作者:行者123 更新时间:2023-12-04 20:32:06 25 4
gpt4 key购买 nike

如果 A Col 有值,则使用以下代码创建下拉列表。
如何设置没有 作为默认值?

  Dim myList As String, r As Range

myList = "Yes,No"

If w1.Range("A" & Rows.Count).End(xlUp).Address <> "$A$1" Then
For Each r In w1.Range("A2", w1.Range("A" & Rows.Count).End(xlUp))
If r.Value <> vbNullString Then
With r.Offset(, 2).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=myList
End With
If r.Offset(, 2).Value = "" Then r.Offset(, 2).Value = "No"
If r.Offset(, 2).Value = "" Then Split myList, ","
End If
Next r
End If

最佳答案

应用 DV 时插入默认值:

代替:

With r.Offset(, 2).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=myList
End With

和:
With r.Offset(, 2).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=myList
End With
r.Offset(, 2).Value = "No"

关于Excel VBA 下拉列表,默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48709306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com