Remove Data Validation with macro

M

Mifty

Hi there,

I thought that this would be easy, what I want to do is remove Data
Validation from ranges in a number of sheets.

I recorded the macro below - but it won't run - runtime error 1004

Application.Goto Reference:="R1C1"
ActiveCell.SpecialCells(xlCellTypeAllValidation).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop,
Operator _
:=xlBetween 'BUGS OUT HERE
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
Cells.Select
Range("B5").Activate
Selection.EntireRow.Hidden = False
Range("H1:H4").Select
Selection.ClearContents
Rows("1:4").Select
Range("B1").Activate
Selection.EntireRow.Hidden = True

Any help would be appreciated

Thank you
 
B

Bob Phillips

This works fine for me

For Each ws In ActiveWorkbook.Worksheets

On Error Resume Next
Set rng = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
If Not rng Is Nothing Then

For Each cell In rng

With cell.Validation
.Delete
.Add Type:=xlValidateInputOnly,
AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween 'BUGS OUT HERE
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
Next cell
End If
Next ws
 
M

Mifty

Hi Bob,

Thanks for responding :)

I'm not sure what I'm doing wrong but I'm still getting a problem
I get a compile error - syntax error now when I try to debug. same bit of code

Cheers
 
B

Bob Phillips

Maybe wrap-around

For Each ws In ActiveWorkbook.Worksheets

On Error Resume Next
Set rng = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0
If Not rng Is Nothing Then

For Each cell In rng

With cell.Validation
.Delete
.Add Type:=xlValidateInputOnly, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
Next cell
End If
Next ws
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top