2017-08-09 91 views
0

我有工作表,它有各種驗證列表,但是對於所有這些列表,我需要用戶可以在單元格中擁有自己的條目。Excel VBA - 手動輸入數據驗證單元格中的數據

我知道你可以取消選擇框,但因爲我的工作表經常重新生成,我需要通過編程實現。任何人有任何想法如何做到這一點?這裏是我的代碼有一個創建下拉列表:

For u = 1 To SpecDependencies.count 
     SpecDepList = SpecDepList & "," & SpecDependencies(u) & " - " & SpecDepDate(u) 
    Next 

    With CRC.Cells(ECURowInCRC, 8).Validation 
     .Delete 
     .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ 
      xlBetween, Formula1:=SpecDepList 
     .IgnoreBlank = True 
     .InCellDropdown = True 
     .InputMessage = "View Spec Dependancies" 
     '.ErrorMessage = "No value selected" 
     .ShowInput = True 
     '.ShowError = True 
    End With 

    End If 

    SpecDepList = "" 
    Set SpecDependencies = New Collection 
    Set SpecDepDate = New Collection 

回答

1

你差點就在您發佈的代碼,只需要改變.ShowError爲false,並且用戶可以輸入任何東西,而不是被警告

For u = 1 To SpecDependencies.count 
    SpecDepList = SpecDepList & "," & SpecDependencies(u) & " - " & SpecDepDate(u) 
Next 

With CRC.Cells(ECURowInCRC, 8).Validation 
    .Delete 
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ 
     xlBetween, Formula1:=SpecDepList 
    .IgnoreBlank = True 
    .InCellDropdown = True 
    .InputMessage = "View Spec Dependancies" 
    '.ErrorMessage = "No value selected" 
    .ShowInput = True 
    .ShowError = False 
End With 

End If 

SpecDepList = "" 
Set SpecDependencies = New Collection 
Set SpecDepDate = New Collection 
+1

嗯,這麼簡單xD不錯的一個老兄謝謝:) – SBozhko

+0

沒有問題在所有的朋友! –