Excel - 来自过滤后的数据验证列表 table
Excel - Data Validation list from filtered table
我正在寻找一种方法,使数据验证列表从过滤后的 table 中提取。
前任。我有一个 sheet 名为 customers 的 table 名为 CustomerList
列 A=客户 B=地址 C=城市 D=州
在另一个名为 Quote 的 sheet 上,我有一个客户名称单元格 C13,它有一个动态范围为 Sheet Customers 列 A Customer 的数据验证列表。在我的列表中,它显示了所有 1800 位客户,即使我过滤 table 以仅显示处于特定状态的客户。我希望能够在 table 上设置过滤器以对我的客户进行排序,并让我的数据验证列表仅显示过滤列表中显示的客户。对于我的生活,我无法弄清楚这一点。任何帮助将不胜感激。 TIA.
在 sheet Customers 中,选择一些单元格并输入:
=SUBTOTAL(103,A:A)
每次更改 A.
列的过滤器时,都会重新计算此公式
在Customersworksheet代码区,安装以下事件宏:
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
每当在 sheet Customers 上修改过滤器时, 单元格 C13 的数据验证 sheet 报价 将更新。
我正在寻找一种方法,使数据验证列表从过滤后的 table 中提取。 前任。我有一个 sheet 名为 customers 的 table 名为 CustomerList 列 A=客户 B=地址 C=城市 D=州 在另一个名为 Quote 的 sheet 上,我有一个客户名称单元格 C13,它有一个动态范围为 Sheet Customers 列 A Customer 的数据验证列表。在我的列表中,它显示了所有 1800 位客户,即使我过滤 table 以仅显示处于特定状态的客户。我希望能够在 table 上设置过滤器以对我的客户进行排序,并让我的数据验证列表仅显示过滤列表中显示的客户。对于我的生活,我无法弄清楚这一点。任何帮助将不胜感激。 TIA.
在 sheet Customers 中,选择一些单元格并输入:
=SUBTOTAL(103,A:A)
每次更改 A.
列的过滤器时,都会重新计算此公式在Customersworksheet代码区,安装以下事件宏:
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
每当在 sheet Customers 上修改过滤器时, 单元格 C13 的数据验证 sheet 报价 将更新。