excel - VBA Loop to target certain cells based on criteria -


i trying achieve macro loops through column d , based on value want color in multiple cells on specific row value exists. needs happen each row meets criteria can seem work when active cell has been selected not automated process. here have far:

sub validate()  dim rng range dim row range dim cell range  set rng = range("d4:d1000")  each cell in rng     if cell.value = "building blocks"         activecell.offset(, 16).interior.colorindex = 7      elseif cell.value = "test"         cell.interior.colorindex = 4      end if next end sub 

any appreciated.

i didn't want rewrite code you, made few changes yours:

sub validate()  dim rng range dim row range dim cell range dim counter long  set rng = range("d4:d1000") range("d4").select  each cell in rng   if cell.value = "building blocks"     activecell.offset(counter, 16).interior.colorindex = 7    elseif cell.value = "test"     activecell.offset(counter, 16).interior.colorindex = 4   end if counter = counter + 1  next end sub 

an better way noted 3-14159265358979323846, take original code , change activecell cell:

sub validate()

dim rng range dim row range dim cell range   set rng = range("d4:d1000")   each cell in rng   if cell.value = "building blocks"     cell.offset(, 16).interior.colorindex = 7    elseif cell.value = "test"     cell.offset(, 16).interior.colorindex = 4   end if   next end sub 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -