excel vba - Conditional formating in VBA, same color, multiple strings? -
i have code conditionnal formating, i'm changing string:
cells.formatconditions.delete range("$a$1:$h$17").formatconditions.add(type:=xltextstring, string:="cpa", textoperator:=xlcontains) .interior.color = rgb(105, 191, 44) end with range("$a$1:$h$17").formatconditions.add(type:=xltextstring, string:="cpn", textoperator:=xlcontains) .interior.color = rgb(105, 191, 44) end with range("$a$1:$h$17").formatconditions.add(type:=xltextstring, string:="css", textoperator:=xlcontains) .interior.color = rgb(105, 191, 44) end with range("$a$1:$h$17").formatconditions.add(type:=xltextstring, string:="rl", textoperator:=xlcontains) .interior.color = rgb(105, 191, 44) end
is there alternative these lines, can write in shorter , more effective way?
this macro colors cells wich contains "cpazergfzergfer". how can write macro color cells containing exact string ?
you use array specify conditions conditional formatting, this:
myarray = array("cpa", "cpn", "css", "rl") myloop = lbound(myarray) ubound(myarray) range("$a$1:$h$17").formatconditions.add(type:=xltextstring, string:=myarray(myloop), textoperator:=xlequal) .interior.color = rgb(105, 191, 44) end next
i've changed textoperator
should select items match text value, rather select items contain text value.
Comments
Post a Comment