Find and Replace Within Validation Limitations

DMumme

New Member
Joined
Jun 14, 2014
Messages
23
I have a worksheet with cells that have validation limitations allowing a list as a source. These cells need to be editable by all users. When changing a validation cell manually, the input is limited to the validation rule assigned. Due to the vast number of cells that may need to be changed at one time, the user may choose to use Find and Replace in Excel to perform the changes. When changing a validation cell(s) using Find and Replace, the validation limitation is ignored and the change(s) are made in violation of the validation limitations.

Is there a way to allow Find and Replace to be used while restricting the replacement input to match the validation requirements for the cell(s)? A VBA alternative (customized Find and Replace) would be an acceptable answer.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Something like this...

Sheet with cells where validation is a fixed A,C,G,T as illustrated:
1579510453817.png


Code, noting this is rudimentary, but conceptually does what you want:
VBA Code:
Sub subReplaceAndCheckValidation()
    f$ = InputBox("Find text")
    r$ = InputBox("Replace text")
    For Each cell In ActiveSheet.UsedRange.Cells
        If cell.Value = f$ Then
            If InStr(cell.Validation.Formula1, r$) > 0 Then
                cell.Value = r$
            Else
                x = MsgBox("Change not allowed for cell " & Split(Cells(1, cell.Column).Address(True, False), "$")(0) & cell.Row, , "Validation issue")
            End If
        End If
    Next cell
End Sub

It will pop up a message box when the replacement text is not in the validation list and not make any changes/skip and move on. This could be extended, of course, to list the cells rather than a message box each time, or abort, etc.

So if find is A and replace is C, all good, but find A and replace U ... no.
 
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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