Excel VBA Loop to fill column based on column header -


so have pivot table updated sql database everyday. want highlight whole section days >5, since data updated daily, conditional formatting not work. created dynamic range (see below), need run loop find column 29 (where days next name) greater 5 need below highlighted in red attachment shows. or suggestions? know pretty complex.

code:

sub dynamicrange()      'disable excel featured whilst macro running     application.calculation = xlcalculationmanual     application.enableevents = false     application.screenupdating = false      'declare variables     dim startcell range, lasrow long, lastcol long, ws worksheet      'set objects     set ws = sheet4     set startcell = range("n30")          'find last row , column of data         lastrow = ws.cells(ws.rows.count, startcell.column).end(xlup).row         lastcol = ws.cells(startcell.row, ws.columns.count).end(xltoleft).column          'select dynamic ramge of data         ws.range(startcell, ws.cells(lastrow - 1, lastcol - 1)).select       're-enable excel features after macro has run     application.calculation = xlcalculationautomatic     application.enableevents = true     application.screenupdating = true 

enter image description here

howdee, should job done you. assign ws variable sheet want run on. let me know if have questions.

sub colorfill() dim ws worksheet dim rngcolor range, rngheader dim lastrow long, lastcol long, firstrow, firstcol  'set sheet desired sheet set ws = sheet1  'find top left of range firstrow = ws.usedrange.row firstcol = ws.usedrange.column  'find bottom right of range lastrow = firstrow + ws.usedrange.rows.count - 1 lastcol = firstcol + ws.usedrange.columns.count - 1  'set range of headers set rngheader = range(cells(firstrow, firstcol + 1), cells(firstrow, lastcol))  'loop through range of headers , color column each cell in rngheader if cell.value > 5     set rngcolor = range(cell.offset(1, 0), cells(lastrow, cell.column))     rngcolor.interior.colorindex = 3 end if next  end sub 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -