i trying select rows in pivot table , highlight them using vba. have been trying few things, have been able highlight 1 cell. below code isn't working, maybe few tweaks fix it. need in vba , not use conditional formatting.
edit: improved code using suggestion answer below , own knowledge. still not working correctly though.
sub highlight() dim fnd variant fnds = array("abc", "dfy", "zxc") = 0 ubound(fnds) cells.find(what:=(fnds), after:=activecell, lookin:=xlformulas, _ lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _ matchcase:=false).activate selection.entirerow.interior .pattern = xlsolid .patterncolorindex = xlautomatic .color = 65535 .tintandshade = 0 .patterntintandshade = 0 end next end sub
by using .find finding first instance of each element of array fnds, wanting? think after every occurrence in case need put loop in there.
also personal preference here prefer create reference cells / rows / columns manipulated actual manipulation once. not such biggy when shading when making changes such deletions , updates can massive process time saver.
sub highlight() dim long, delrange string = 1 cells(rows.count, 1).end(xlup).row if instr(1, cells(i, 1), "abc") <> 0 or instr(1, cells(i, 1), "dfy") <> 0 or instr(1, cells(i, 1), "zxc") <> 0 delrange = delrange & "," & & ":" & next range(right(delrange, len(delrange) - 1)).interior .pattern = xlsolid .patterncolorindex = xlautomatic .color = 65535 .tintandshade = 0 .patterntintandshade = 0 end end sub
Comments
Post a Comment