2017-07-26 40 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