ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compare Validation Operator give error (https://www.excelbanter.com/excel-programming/378501-compare-validation-operator-give-error.html)

tskogstrom

Compare Validation Operator give error
 
Hi,

I have code to restore validation in cells if any paste over new cells.
I have noticed that changing validation demand a unprotected workbook
and unprotection empty the clipbook. Since I don't wan't to empty the
clipbook, I try to check if there is a validation and if it is - if it
is right one. With this, I just empty clipbook if I need to.
- This done by trying to compare Operators as following code:

BUT I get 1004 error on "If .Operator = .." line. Why?
Can anybody see the reason?
Kind regards
/tskogstrom


Sub ValidationPercent(rng As Range)

If Not rng.Validation Is Nothing Then ' if validation- is it correct
one?
With rng.Validation
If .Operator = xlBetween Then
If .Formula1 = "0" And .Formula2 = "100" Then
GoTo endcode
Else:
GoTo validationcode
End If
End If
End With
Else:
GoTo validationcode
End If
Exit Sub

validationcode:
Call UnProtectWB
With rng.Validation
.Delete
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop,
_
Operator:=xlBetween, Formula1:="0", Formula2:="100"
.IgnoreBlank = False
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Call ProtectWB
endcode:
End Sub



All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com