VBA for overlaying a smaller table Drop Down list -
here following vba , works ok: - have couple of tables , used named ranges each of them. - then, on different tab (where code is) have 2 drop down lists users of excel report can select table (only 1 @ time) want display data for.
the problem me if select table drop down has 30 rows looks fine - table destination cell a2. if select table has 10 rows, new table 10 rows overlaid on previous 30 row table 20 rows(remaining 30 row table) under 10 row table still there.
my question is: how should change code below 20 rows previous table not appear when 10 rwo table selected drop down list?
let me know if above doesn't make sense..thanks v much.
my code @ minute follows:
private sub worksheet_change(byval target range) dim tablename string dim tablerange range dim typeofcosts string application.enableevents = false if range("b1").text = "fixed staff costs" typeofcosts = "_fixed_staff" elseif range("b1") = "variable staff costs" typeofcosts = "_variable_staff" elseif range("b1") = "production costs" typeofcosts = "_production" elseif range("b1") = "infrastructure costs" typeofcosts = "_infrastructure" elseif range("b1") = "other costs" typeofcosts = "_other" else typeofcosts = "" end if tablename = range("a1").text & typeofcosts & "_costs" on error resume next set tablerange = application.range(tablename) debug.print thisworkbook.names.count if not (tablerange nothing) , err = 0 tablerange.copy destination:=range("a3") else err.clear end if on error goto 0 application.enableevents = true end sub
this pretty blunt approach, without knowing more setup:
with range("a3").resize(1000,10) .clearcontents .clearformats end
Comments
Post a Comment