excel - VBA Data Validation List Selection -
i'm writing code embed in 1 table. situation this: cell a1 (with option of 50,100 , 150) , cell a2 (with option of 1000 , 5000), both have data validation list in them. when choose cell a1 of 50, a2 has 1000. when wrote code , made selection, there error:
run-time error '-2147417848(80010108)': method 'add' of object 'validation' failed.
please share opinions or if need post codes here resolve issue.
the basic code following:
select case range("a1").value case "50" range("a2").clearcontents range("a6").value2 = "1000" case "`100" range("a2").clearcontents range("a2").validation .delete .add type:=xlvalidateinputonly, alertstyle:=xlvalidalertstop, operator _ :=xlbetween .ignoreblank = true .incelldropdown = true .inputtitle = "" .errortitle = "" .inputmessage = "" .errormessage = "" .showinput = true .showerror = true end range("a2").value2 = 1000
add code module of sheet cells want validation added
private sub worksheet_change(byval target range) if target.address = "$a$1" if target.value = 50 range("a2") = 1000 ' add valid values of 1000 allowed range("a2").validation .delete .add type:=xlvalidatelist, alertstyle:=xlvalidalertstop, operator:=xlbetween, formula1:="1000" .ignoreblank = true .incelldropdown = true .inputtitle = "" .errortitle = "" .inputmessage = "" .errormessage = "enter valid value" .showinput = false .showerror = true end else ' add valid values of 1000 , 5000 allowed range("a2").validation .delete .add type:=xlvalidatelist, alertstyle:=xlvalidalertstop, operator:=xlbetween, formula1:="1000,5000" .ignoreblank = true .incelldropdown = true .inputtitle = "" .errortitle = "" .inputmessage = "" .errormessage = "enter valid value" .showinput = false .showerror = true end end if end if end sub
Comments
Post a Comment