Unable to clear the contents of Datavalidation in excel using VBA -
i have vba function bind array excel range , in turn use range specify data validation list selected range.
below function create datavalidation list.
private function createdatavalidation(byval pobjrange range, byval pvararrayentries variant) boolean const picklist_column = "iv" createdatavalidation = true if ubound(pvararrayentries) = 0 pobjrange.validation.delete else ' ' select range ' dim lobjpicklistrange range set lobjpicklistrange = application.activesheet.range(cells(1, picklist_column), cells(ubound(pvararrayentries) + 1, picklist_column)) ' ' clear existing column ' lobjpicklistrange.clear ' ' write entries picklist column ' lobjpicklistrange = pvararrayentries dim lstrformula string lstrformula = "=" & picklist_column & "1:" & picklist_column & ubound(pvararrayentries) + 1 if application.referencestyle = xlr1c1 lstrformula = application.convertformula(lstrformula, xla1, xlr1c1) end if pobjrange.validation .delete .add type:=xlvalidatelist, alertstyle:=xlvalidalertstop, operator:= _ xlbetween, formula1:=lstrformula .ignoreblank = true .incelldropdown = true .inputtitle = "" .errortitle = "" .inputmessage = "" .errormessage = "" .showinput = true .showerror = true end end if end function
issue that, when bind range array values drop down appears, when select same range , pass empty array above method drop down doesn't disappear. means code in function
if ubound(pvararrayentries) = 0 pobjrange.validation.delete doesn't work. in clearing range contains datavalidation drop down of great help. tried range.clearcontents , validation.delete nothing worked.
for information,the above function called on workbook_sheetselectionchange event
thanks in advance.
i find workaround problem, setting incelldropdown false, way if array has no elements, setting above property false drop down not visible , user not able set value. inputs.
Comments
Post a Comment