2017-07-26 51 views
0

我在WorkSheet(PartsList)上有一个简单的数据列,它可以从各自的行中过滤数据。在同一工作簿中的另一个WorkSheet(BoM)上,我通过数据验证“列表”引用此列。数据验证下拉列表不自动更新

我遇到的问题是当'PartsList'WorkSheet中的数据更新时,下拉列表中显示的信息保持不变。

正如您在下图中看到的,虽然'Part Number'和'Variant'列有下拉列表没有更新'part#'。 enter image description here enter image description here

这里是生成列表中的公式:反正做下拉列表自动更新的 enter image description here 是吗?

+0

如何定义数据验证列表?没有看到在这里很难帮助。 –

+0

您是否编辑了数据验证的源范围? – dwirony

+0

我已经添加了数据验证设置和生成列表的公式的图像。 –

回答

0

在后台编写一个vba代码,每当工作簿打开时它就会更新列表。 步骤1:根据零件清单中的行数,编写一个将数据验证文件添加到列的vba代码。 步骤2:使用workbook_open fn在打开工作簿时运行宏

0

我设法解决了这个问题。

我在网上发现了一些VBA代码,并在必要时进行了更改。请参阅下面的代码和解释说明,包括

Option Explicit 

Private Sub Worksheet_Change(ByVal Target As Range) 
' Ensure all lists are made from tables and that these tables are named 
' in the Name Manager. 
' When creating your Data Validation List, instead of selecting a range 
' in 'Source', click within 'Source' and press 'F3'. Finally select your 
' tables name. 
Dim strValidationList As String 
Dim strVal As String 
Dim lngNum As Long 

On Error GoTo Nevermind 
strValidationList = Mid(Target.Validation.Formula1, 2) 
strVal = Target.Value 
lngNum = Application.WorksheetFunction.Match(strVal, ThisWorkbook.Names(strValidationList).RefersToRange, 0) 

' Converts table contents into a formula 
If strVal <> "" And lngNum > 0 Then 
    Application.EnableEvents = False 
    Target.Formula = "=INDEX(" & strValidationList & ", " & lngNum & ")" 
End If 

Nevermind: 
    Application.EnableEvents = True 

End Sub