vba - Conditional formatting, select only visible cells -


i have written code select specific sheets , on button click email data of selected sheets. in 1 sheet there conditional formatting applied on dropdown list.

so requirement when dropdown option 1 chosen, below 2 cells not visible. secondly when dropdown option 2 selected cells visible.

with code gets selected.

i tried code :

overallrange = activesheet.range("c1:d50").specialcells(xlcelltypevisible).select  

can advice better ways this....

you're headed right way, see sniplet below:

sub ert()  dim rng range each rng in activesheet.range("c1:d50").specialcells(xlcelltypevisible)     rng.select     selection         .formatconditions.add type:=xlexpression, formula1:="=true" 'replace formula         .formatconditions(selection.formatconditions.count).setfirstpriority         .formatconditions(1).stopiftrue = false         .formatconditions(1).interior.color = 49407 'give touch of orange     end next  end sub 

p.s. noone tell him, gotta love 1st of april. come tomorrow.
edit, more heat: let me highlight .select method emulates selecting range selection. refers range selected. select in code wastes resource , can cause errors (e.g. cannot selected macro halts, selectionchange event triggers etc.) , looks lousy. above reasons (esp. lousiness) don't select, define range , run script given range. way can save seconds of runtime while looking cool. snipplet below cool variation of sub-sub.

sub ert()     activesheet.range("c1:d50").specialcells(xlcelltypevisible)         .formatconditions.add type:=xlexpression, formula1:="=true" 'replace formula         .formatconditions(.formatconditions.count).setfirstpriority         .formatconditions(1).stopiftrue = false         .formatconditions(1).interior.color = 49407 'give touch of orange     end end sub 

Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -