Hi folks,
I'm using a piece of code to Data-Validate a couple of columns and it keeps falling over with the error message:
Run-Time Error '-2147417848 (80010108)': Automation error. The object invoked has disconnected from its clients.
The code stops at the red line below:
Private Sub Data_Validate()
Dim FirstWS As Integer, LastWS As Integer, M As Integer
FirstWS = 6
LastWS = 12
For M = FirstWS To LastWS
With Sheets(M)
With Columns("C:C").Validation
.Delete
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlLessEqual, Formula1:="41"
.IgnoreBlank = True
.InCellDropdown = True
.ErrorTitle = "Leave Programme"
.ErrorMessage = "You must enter a numeric value"
.ShowInput = False
.ShowError = True
End With
With Columns("B:B").Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="4/1/2008", Formula2:="3/31/2009"
.IgnoreBlank = True
.InCellDropdown = True
.ErrorTitle = "Leave Programme"
.ErrorMessage = _
"Ensure that the date entered is between 01/04/2008 and 31/03/2009"
.ShowInput = False
.ShowError = True
End With
End With
Next M
End Sub
Can anyone enlighten me why this happens, please?
Seamus
Bookmarks