Application-Defined or Object-Defined error

3link

Board Regular
Joined
Oct 15, 2010
Messages
138
I have a macro that deletes validation criteria within a few ranges and implements new criteria when activated. It looks like this:

Code:
ActiveSheet.Unprotect
With Range("H10").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=PTsRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H10] = Range("BM43").Value
 
  With Range("H16").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=LrRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H16] = Range("BQ44").Value
 
   With Range("H22").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=RcRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H22] = Range("BS44").Value
 
    With Range("H28").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=LgRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H28] = Range("BU44").Value
 With ActiveSheet.SpinButton6
       .Min = 0
       .Max = Range("BN44").Value
       .Value = Range("BN44").Value
       End With
With ActiveSheet.SpinButton7
       .Min = 0
       .Max = Range("BQ44").Value
       .Value = Range("BQ44").Value
       End With
With ActiveSheet.SpinButton8
       .Min = 0
       .Max = Range("BS44").Value
       .Value = Range("BS44").Value
       End With
With ActiveSheet.SpinButton9
       .Min = 0
       .Max = Range("BU44").Value
       .Value = Range("BU44").Value
       End With
       ActiveSheet.Protect

The named ranges (PTsRange, LRrange, RCrange and LGrange) are all labeled and functioning properly. I tested them on separate validation lists to confirm. However, I still get this Application-Defined or Object-Defined error run-time error. When I get it,

Code:
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=LrRange"

is highlighted.

Thus, the error must be in the way the macro is coded. I can't see a darn thing wrong with it. Anyone have any ideas?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Wow, I get exactly the same error from the exact cause ... strange nobody has replied. Is it a very complex issue this one?:eeek:

rng is a valid range (I've verified its address using the immediate window)

With rng
With .Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & rList
End With
End With

I have a macro that deletes validation criteria within a few ranges and implements new criteria when activated. It looks like this:

Code:
ActiveSheet.Unprotect
With Range("H10").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=PTsRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H10] = Range("BM43").Value
 
  With Range("H16").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=LrRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H16] = Range("BQ44").Value
 
   With Range("H22").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=RcRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H22] = Range("BS44").Value
 
    With Range("H28").Validation
 .Delete
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=LgRange"
 .ErrorMessage = "Invalid value. Select one from the dropdown list."
 .InCellDropdown = True
 End With
 Sheets("Trends").[H28] = Range("BU44").Value
 With ActiveSheet.SpinButton6
       .Min = 0
       .Max = Range("BN44").Value
       .Value = Range("BN44").Value
       End With
With ActiveSheet.SpinButton7
       .Min = 0
       .Max = Range("BQ44").Value
       .Value = Range("BQ44").Value
       End With
With ActiveSheet.SpinButton8
       .Min = 0
       .Max = Range("BS44").Value
       .Value = Range("BS44").Value
       End With
With ActiveSheet.SpinButton9
       .Min = 0
       .Max = Range("BU44").Value
       .Value = Range("BU44").Value
       End With
       ActiveSheet.Protect

The named ranges (PTsRange, LRrange, RCrange and LGrange) are all labeled and functioning properly. I tested them on separate validation lists to confirm. However, I still get this Application-Defined or Object-Defined error run-time error. When I get it,

Code:
 .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
 Operator:=xlBetween, Formula1:="=LrRange"

is highlighted.

Thus, the error must be in the way the macro is coded. I can't see a darn thing wrong with it. Anyone have any ideas?
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

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