0
我有VBA代碼來更改單元上的驗證取決於所選的選項。VBA驗證崩潰我的工作簿
Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Sheets("lkup")
Dim VariationList As Variant
VariationList = Application.Transpose(ws.Range("Resource_List"))
For i = LBound(VariationList) To UBound(VariationList)
Next i
If Target = Range("B15") Then
If InStr(1, Range("B15"), "Resource") > 0 Then
With Range("D15").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlEqual, Formula1:=Join(VariationList, ",")
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ElseIf InStr(1, Range("B15"), "Fixed Asset") > 0 Then
Range("D15").Validation.Delete
Range("D15").ClearContents
With Range("D15").Validation
.Delete
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="100000", Formula2:="999999"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Oopps"
.InputMessage = ""
.ErrorMessage = "Your fixed asset number can only be 6 numbers"
.ShowInput = True
.ShowError = True
End With
Else
Range("D15").ClearContents
Range("D15").Validation.Delete
End If
End If
End Sub
它工作而工作簿打開。它運行良好,沒有錯誤或任何事情。然而,當我保存並重新打開工作簿,它給了我下面的:
我們發現一個問題,在「Invoice.xlsm」一些內容。你想我們 儘可能多地恢復?如果您信任此 工作簿的來源,請單擊是。
然後打開工作簿,去掉我所有的格式並刪除VBA。
我試過谷歌搜索,但一直沒有能夠翻譯到我有。
乾杯,
你,我的朋友是絕對的明星! –
謝謝。我對自己的努力方式瞭解了EnableEvents – 2016-11-16 02:39:44