VBA Validation error

Donai

Well-known Member
Joined
Mar 28, 2009
Messages
543
Hi, i am getting application object defined error on the below, could you please explain why?

Code:
With .Range("A6:A" & lDstRowNum).Validation
                    .Delete
 [COLOR=red][B]                   .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=rngName"
                End With[/B][/COLOR]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Works fine for me. You might delete the Operator argument, which isn't needed:

Code:
    With Range("A6:A" & lDstRowNum).Validation
        .Delete
        .Add Type:=xlValidateList, _
             AlertStyle:=xlValidAlertStop, _
             Formula1:="=rngName"
    End With
 
Upvote 0
Is it because the named range is dynamic?

Works fine for me. You might delete the Operator argument, which isn't needed:

Code:
    With Range("A6:A" & lDstRowNum).Validation
        .Delete
        .Add Type:=xlValidateList, _
             AlertStyle:=xlValidAlertStop, _
             Formula1:="=rngName"
    End With
 
Upvote 0
When i run in excel 2010 the code runs perfectly but when i run in 2002 i get an error. Also i am running the code through command button macro but if i run the macro on it own through ALT F8 then it works, very strange.
 
Upvote 0
This is the dynamic formula "rngName" am i correct to use this formula for my list?

=OFFSET(Assumptions!$E$20,0,0,COUNTA(Assumptions!$E:$E),1)
 
Upvote 0
Could it be something to do with

TakeFocus on click? Should this be set to FALSE?
 
Upvote 0
When i run in excel 2010 the code runs perfectly but when i run in 2002
I don't have either of those versions.

=OFFSET(Assumptions!$E$20,0,0,COUNTA(Assumptions!$E:$E),1)

That's a volatile range name. You might replace it with

=$E$20:INDEX($E:$E, MATCH(9E307, $E:$E))

or

=$E$20:INDEX($E:$E, MATCH(REPT("z", 255), $E:$E))

... depending on whether there are numbers or text in the range.
 
Upvote 0
Ok i tried that but i still get 1004-application object defined error. Everytime i open the file and run the macro i get the error, but the second time i run it works. This is only in Excel 2002 not 2010, and only when i run the code from another sheet via command button code.

Is there another method to add list?

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

I don't have either of those versions.



That's a volatile range name. You might replace it with

=$E$20:INDEX($E:$E, MATCH(9E307, $E:$E))

or

=$E$20:INDEX($E:$E, MATCH(REPT("z", 255), $E:$E))

... depending on whether there are numbers or text in the range.
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

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