我有兩組動態列表,List1
&List2
清單是使用 OFFSET 和 COUNTA 建立的,因此新條目包含在清單等中。
在儲存格 A1 中,我想使用資料驗證列表功能,但我希望它引用這兩個列表,
有人告訴我這需要透過 VBA 來完成?
有什麼建議 ?
我目前使用:
=(COUNTIF(list1,A1)+COUNTIF(list2,A1))>=1
在“自訂”部分,但這不允許我擁有清單下拉選項
答案1
您可以使用巨集將值強制放入單一清單中
Sub Validation()
Dim a$, el As Range
' SET THE LIST RANGE, YOU CAN USE MORE THAN 2
Dim rng1 As Range, rng2 As Range
'DEFINE THE CELLS USED FOR THE LIST, NAMED RANGE OR INDIRECT CAN BE USED
Set rng1 = Range("List1")
Set rng2 = Range("List2")
'COLLECT VALUES FROM LISTS
For Each el In rng1
a = a & el.Value & ","
Next
For Each el In rng2
a = a & el.Value & ","
Next
' SET DESTIANTION OF DATA VALIDATION RULE
With Range("A1").Validation
.Delete
.Add Type:=xlValidateList, Formula1:=a
End With
Set rng1 = Nothing
Set rng2 = Nothing
End Sub
唯一的缺點是,每次向清單中新增值時都需要執行宏,您可以透過工作簿變更將其放入