Update Validation in Merged Cells

MartinS

Active Member
Joined
Jun 17, 2003
Messages
490
Office Version
  1. 365
Platform
  1. 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?
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top