excel - Conditional cell fill code to apply to several rows with different conditions for each row -
i trying write conditional cell fill code using vba having syntax issues. realize there tab this, need apply code several different rows different conditions each row code faster purposes. pretty new vba think got logic correct @ least.
basically there lead column value each value in following columns needs tested against.
(test value) | (value tested)| (value tested)... (test value) | (value tested)| (value tested)... if value greater or less test value 3 units cell needs turn red, otherwise needs green.
here did. used button macro if there way automatically without button that'd best.
i keep getting run time error "1004" ; application or object defined error on line five. using nested set of loops. first loop selects row , picks test value row. maybe assigning variable wrong or need select worksheet working in? next part of loop tests following values in each row see if inside or outside specified range of test value. lastly cell colored based on determination.
code:
private sub commandbutton21_click() dim integer, j integer, t integer, r integer 't cell want test, r integer want use test t = 6 132 r = cells(6, j).value j = 4 1000 'loop through each column test each cell (move right down selected row) t = cells(i, j).value 'test each cell if t < (r - 3) or t > (r + 3) cells(i, j).interior.colorindex = 4 else cells(i, j).interior.colorinex = 3 end if next j next end sub i tried using cell formula editor apply code don't believe can change cell color way:
"=if(or(d6<$c$6-3,d6>$c$6+3),"change color red","change color green""
move following line down 1 line (it's before assigned value j):
r = cells(6, j).value
Comments
Post a Comment