MartinS
Active Member
- Joined
- Jun 17, 2003
- Messages
- 490
- Office Version
- 365
- Platform
- Windows
The idea is to simplify the validation for all cells on specific tabs that contain a certain validation formula, but what I'm finding is that it is applying the validation to each cell of a merged cell.
i.e. cells E54 (merged with F54) contains the specific validation, so I only want to set the validation for E54, but my code is applying the validation to F54 as well!
What am I missing?
i.e. cells E54 (merged with F54) contains the specific validation, so I only want to set the validation for E54, but my code is applying the validation to F54 as well!
What am I missing?
VBA Code:
Sub UpdateValidation()
'Declare procedure level variables
Dim wks As Worksheet
Dim rngSpecialCells As Range
Dim rngCell As Range
'Loop through evert worksheet
For Each wks In ThisWorkbook.Worksheets
'Only interested in specific tabs
If InStr(1, wks.Name, "Basis Switch", vbTextCompare) > 0 Then
'Unprotect the sheet
wks.Unprotect
'Get all the cells that contain a validation rule
Set rngSpecialCells = wks.Cells.SpecialCells(xlCellTypeAllValidation)
For Each rngCell In rngSpecialCells
If rngCell.Validation.Type = xlValidateList Then
If rngCell.Validation.Formula1 = "=IF(AND(VBSComp_CurvesUsed=SelectYes,VBSComp_Steps=SelectTwoStep),SelectRuns2Step,SelectRuns1Step)" Then
With rngCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=SelectRuns1Step"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = False
End With
End If
End If
Next rngCell
'Re-protect the worksheet
wks.Protect
End If
'Repeat for the next sheet
Next wks
End Sub