excel - VBA If cell is under a certain length, highlight and display message -
i'm trying write macro examines column in excel spreadsheet looking entries shorter 9 characters greater 2, , if found, display message , highlight cell in value found. might happen multiple times. have written following code:
sub highlight() dim c range dim lr integer dim intcell long lr = worksheets("basket").cells(rows.count, 6).end(xlup).row intcell = 1 8 each c in range("g20:g" & lr).cells if len(c.value) < 9 , len(c.value) > 2 msgbox "one or more of codes invalid. correct highlighted values." c.cells(intcell).interior.color = vbyellow end if next next end sub
i can't figure out i'm doing wrong. appreciated.
just guessing @ want highlight
sub highlight() dim c range dim lr integer dim numprobs long dim sht worksheet set sht=worksheets("basket") numprobs=0 lr = sht.cells(rows.count, "g").end(xlup).row each c in sht.range("g20:g" & lr).cells if len(c.value) < 9 , len(c.value) > 2 c.entirerow.cells(1).resize(1,8).interior.color = vbyellow numprobs=numprobs+1 end if next if numprobs>0 msgbox "there issues " & numprobs & " rows. see yellow cells" end if end sub
Comments
Post a Comment