Excel – 来自过滤表的数据validation列表

我正在寻找一种方法来从一个过滤的表中拉数据validation列表。 防爆。 我有一张名为CustomerList列的表A =客户B =地址C =城市D =州在名为Quote的另一个工作表中,单元格C13为客户名称,其数据validation列表为Sheet Customers列的dynamic范围一个客户。 在我的列表中,即使我筛选表格以仅显示处于特定状态的客户,也会显示全部1800个客户。 我希望能够在表格上设置filter来对我的客户进行分类,并让我的数据validation列表只显示过滤列表中显示的客户。 对于我的生活,我无法弄清楚这一点。 任何帮助将不胜感激。 TIA。

在表单Customers中 ,select一些单元格并input:

=SUBTOTAL(103,A:A) 

每当filter更改为A列时,将重新计算此公式。

客户工作表代码区域中,安装以下事件macros:

 Private Sub Worksheet_Calculate() Call makeDV End Sub 

在标准模块中,安装以下代码:

 Public DVList As String Public Sub makeDV() Dim A As Range, r As Range Dim c As Collection, v As Variant Set c = New Collection Set A = Intersect(Range("A2:A" & Rows.Count), ActiveSheet.UsedRange).Cells.SpecialCells(xlCellTypeVisible) DVList = "" On Error Resume Next For Each r In A v = r.Value If v <> "" Then c.Add v, CStr(v) If Err.Number = 0 Then DVList = DVList & "," & v Else Err.Clear End If End If Next r If Len(DVList) <> 0 Then DVList = Mid(DVList, 2) On Error GoTo 0 Dim Quote As Worksheet Set Quote = Sheets("Quote") With Quote.Range("C13").Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:=DVList .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With End Sub 

无论何时在表单Customers上修改filter,表单报价单元格C13的数据validation都将更新。