Validation.Formula1 error

croco1

New Member
Joined
Nov 30, 2016
Messages
10
Hi all,

I get an run-time error 1004 in the code below in row: If rCell.Validation.Formula1 = "EUR" Then

Can somebody help me?


Sub test()
Dim rCell As Range
If Selection.Cells.Count = 1 Then
MsgBox "Select the range to be processed."
Exit Sub
End If
For Each rCell In Selection
If rCell.Validation.Formula1 = "EUR" Then
rCell.Validation.Delete
rCell.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=ListCurrency"
End If
Next rCell
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
When a cell does not contain any validation errors, it throws up an error. Thats what is happening

If thats the only possible cause of an error(a big assumption), then

Rich (BB code):
Sub test()
    Dim rCell As Range
    If Selection.Cells.Count = 1 Then
        MsgBox "Select the range to be processed."
        Exit Sub
    End If
    For Each rCell In Selection
        On Error Resume Next
        If rCell.Validation.Formula1 = "EUR" Then
            rCell.Validation.Delete
            rCell.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=ListCurrency"
        End If
    Next rCell
End Sub
 
Upvote 0
Unfortunately the validation with formula1:="=ListCurrency" is applied to EACH cell in the selected area, while it only needs to change the cells which already have a validation with formula1:="EUR".
 
Upvote 0
If all cells need validation listcurrency why not delete all validation and reapply?
 
Upvote 0
I have a large workbook and only CERTAIN cells have a validation. I need to replace the validation in the cells that have "EUR" in formula1 and only replace these with "=ListCurrency", while ommiting cells without validation or with different validation than "EUR". The workbook is too large to reapply manually the specific cells.
 
Upvote 0
Make your mind up. You just said:

'Unfortunately the validation with formula1:="=ListCurrency" is applied to EACH cell in the selected area'

Which is it?
 
Upvote 0
Sorry for being unclear. 'Unfortunately the validation with formula1:="=ListCurrency" is applied to EACH cell in the selected area' was my response to Momentman's solution. So it should only apply to certain cells ("EUR") while his solution enters a validation.formula1 with "=ListCurrency" in all cells in a selected area.
 
Upvote 0
See if this does it:

Code:
On Error GoTo 0
Set Rng = Selection.SpecialCells(xlCellTypeAllValidation)
With Rng.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=ListCurrency"
End With
 
Upvote 0
It now changes all cells that have a validation. I would like to only change the ones with Formula1:="EUR".
 
Upvote 0
Ok lets try:

Code:
On Error GoTo 0
Set Rng = Selection.SpecialCells(xlCellTypeAllValidation)
If Not Rng Is Nothing Then
    For Each c In Rng
        With c.Validation
            If .Formula1 = "EUR" Then
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=ListCurrency"
            End If
        End With
    Next
End If
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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