[英]Worksheet_change event - change cell value on all sheets when selecting from drop-down list
[英]Excel VBA - Worksheet_Change drop-down list
您好Stackoverflow社區,
如果要滿足條件,我想添加一個數據驗證下拉列表。
使用Excel VBA,我想添加下拉列表以在N列(我的帳戶狀態)中填充,只要單詞“ Final Recon”出現在C列即我的評估狀態,但僅在單詞“ Final Recon”出現時填充出現在列C中。
使用Excel VBA-私人子Worksheet_Change(以ByVal目標為范圍):
如果“最終偵查”出現在列C中,則使用以下狀態填充下拉列表:“最終”或“審核中”,否則不要填充下拉列表。
我可以使用非VBA驗證列表,但是在這種評估類型中,我需要使用VBA版本。
到目前為止,這就是我所擁有的,而且我非常困窘。 我在C列中有“最終偵查”,如果最終偵查出現在C列中,則使用“最終”和“正在審核”選項填充下拉列表。
但是由於某種原因,當Final Recon出現在C列時,drop-dwon列表沒有填充在N列中。
預先感謝您提供的任何幫助或解決方案。
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Then
ThisRow = Target.Row
If Target.Value = "Final Recon" Then
With Selection.Validation
.Range ("N" & ThisRow)
.Delete
.Add Type:=xlValidateList, Formula1:="=Final", Formula2:="=Under Review"
End With
Else
Range("N" & ThisRow) = ""
End If
End If
End Sub
我能夠弄清楚。 我唯一的問題是,如果“ Final Recon”不在“ C”列中,則下拉列表不顯示。
On Error Resume Next
If Target.Column = 3 Then
If Target.Validation.Type = "Final Recon" Then
Application.EnableEvents = False
''get the data drop-down validation list
Target.Offset(0, 11).Select
With Selection.Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop
Operator:=xlBetween, _
Formula1:="Final", Formula2:="Under Review"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Else
Target.Offset(0, 11).Value = ""
End If
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.