Identifying and highlighting a blank row in Excel VBA -
scenario: each row contain 23 columns; 20 contain user populated data , last 3 autogenerated through vba. while running if vba code identifies first 20 columns of row blank cells whole row declared blank , highlighted.
i have been able write following code:
each rng in range("a1:a" & lastrow) rng if .value < 1 msgbox "blank cell found" blnkcnt = 0 each mycl in range("a" & activecell.row & ":t" & activecell.row) mycl if .value < 1 blnkcnt = blnkcnt + 1 end if end next mycl if blnkcnt = 20 lcount = lcount + 1 .entirerow.interior .colorindex = 6 .pattern = xlsolid .patterncolorindex = xlautomatic end end if end if end next rng if lcount > 0 msgbox "data contains blank row(s): " & lcount end else msgbox "no blank rows" end if
i've used countblank function on first 20 columns of each row determine if blank cells exist.
dim rng range, lcount long, lastrow long activesheet 'set worksheet properly! lastrow = .cells(rows.count, 1).end(xlup).row each rng in .range("a1:a" & lastrow) rng.resize(1, 20) if application.countblank(.cells) = 20 'all 20 cells blank lcount = lcount + 1 .entirerow.clearcontents .entirerow.interior.colorindex = 6 end if end next rng end if lcount > 0 msgbox "data contains blank row(s): " & lcount else msgbox "no blank rows" end if
if 20 cells blank entire row made blank , yellow highlighting applied.
i'm using countblank function not clear on whether have zero-length strings returned formulas. countblank count these blanks.
Comments
Post a Comment