Excel VBA - Loop needed for a column -


i'm new excel vba , can't figure out how work. have column (column k), header in k1. spreadsheet every day , has different number of rows. column k has numbers 0-100. need highlight rows colors depending on value in column k. have far, goes way down , makes every column red font. need loop through k2 last k cell value , change font color of each row.

columns("k").select dim firstcell integer dim finalcell integer firstcell = range("k2") finalcell = range("k65536").end(xlup).row = firstcell finalcell  if > 5     rows(i).select     selection.font         .color = rgb(255, 0, 0)     end elseif = 4     rows(i).select     selection.font         .color = rgb(226, 107, 10)     end elseif = 3     rows(i).select     selection.font         .color = rgb(0, 176, 80)     end elseif = 2     rows(i).select     selection.font         .color = rgb(0, 112, 192)     end elseif = 1     rows(i).select     selection.font         .color = rgb(112, 48, 160)     end end if next 

in if statements you're referencing i, not value contained in column k , row seem want.

so change if statements from:

if > 5 'and elseif = 4 

to:

if range("k" & i).value > 5 'and elseif range("k" & i).value = 4 

for if statements. change first , final cell statements. might, work, know these will:

finalcell = activesheet.range("k" & activesheet.rows.count).end(xlup).row 'and  firstcell = 2 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -