excel - VBA iteration loop -
i need highlight cells in each row in excess of value in column au row of data; next row, cannot value of column au
iterative meaning changing next row's value.
let me know i'm doing wrong here.
sub highlight() application.screenupdating = false dim myrange range dim long, j long set myrange = range("f11:ap20") n = 11 20 = 1 myrange.rows.count j = 1 myrange.columns.count if myrange.cells(i, j).value < range(aun).value myrange.cells(i, j).interior.color = 65535 else myrange.cells(i, j).interior.colorindex = 2 end if next j next next n end sub
- you have 1 loop extra
aun
being treated blank variable. guess want work relevant row in col au.
is trying? (untested)
i have commented code let me know if still have questions :)
sub highlight() application.screenupdating = false dim myrange range dim n long, j long dim ws worksheet '~~> change relevant worksheet set ws = thisworkbook.sheets("sheet1") ws '~~> set range set myrange = .range("f11:ap20") '~~> loop through rows (11 20 in case) n = myrange.row (myrange.row + myrange.rows.count - 1) '~~> loop through columns (f ap in case) j = myrange.column (myrange.column + myrange.columns.count - 1) if .cells(n, j).value < .range("au" & n).value .cells(n, j).interior.color = 65535 else .cells(n, j).interior.colorindex = 2 end if next j next n end end sub
Comments
Post a Comment