Using Excel VB to change imported data from Access colour coded accordingly -


what i'm trying change specific range cells specific colours. works when there increase , when more -2.00% should red. however, when decreasing previous time should green, , once below -2.00% should go black again.

so cell data in starts @ c2 , ends @ h54. works in row format c2 main d2 continue data, etc. c3 new main data , d3 continue of data, etc.

my code have been testing not getting right follows:

range("c2").select if range("c2").value >= "-2.00%" selection.font .color = -16776961 .tintandshade = 0 end elseif range("c2").value < "-2.00%" selection.font .themecolor = xlthemecolorlight1 .tintandshade = 0 end end if  range("d2").select if range("d2").value <= "-2.00%" & range("c2").value selection.font .color = -11489280 .tintandshade = 0 end elseif range("d2").value > "-2.00%" & range("c2").value selection.font .color = -16776961 .tintandshade = 0 end elseif range("d2").value < "-2.00%" selection.font .themecolor = xlthemecolorlight1 .tintandshade = 0 end end if  range("e2").select if range("e2").value <= "-2.00%" & range("d2").value selection.font .color = -11489280 .tintandshade = 0 end elseif range("e2").value > "-2.00%" & range("d2").value selection.font .color = -16776961 .tintandshade = 0 end elseif range("e2").value < "-2.00%" selection.font .themecolor = xlthemecolorlight1 .tintandshade = 0 end end if 

however, when goes below 2.00% still green, , same error stays when increase again...

i appreciate assistance in getting done asap... if know of shorter method please put down me test out. thank taking time review this.

here sample picture of result , should be: enter image description here

this seems follow business logic perceive code , sample image(s).

sub ject()     dim r long, c long, vrtrns variant, thrshld double      thrshld = 0.02      worksheets("sheet2")         .cells(1, 1).currentregion             .resize(.rows.count - 1, .columns.count - 2).offset(1, 2)                 .cells.font.colorindex = xlcolorindexautomatic                 vrtrns = .value2                 r = lbound(vrtrns, 1) ubound(vrtrns, 1)                      'deal first value                     if vrtrns(r, lbound(vrtrns, 2)) >= thrshld                         .cells(r, 1).font.color = vbred                     end if                      'the remainder of columns in row                     c = lbound(vrtrns, 2) + 1 ubound(vrtrns, 2)                         select case vrtrns(r, c)                             case >= thrshld                                 .cells(r, c).font.color = _                                     iif(vrtrns(r, c) >= vrtrns(r, c - 1), vbred, vbgreen)                             case < thrshld                                 .cells(r, c).font.colorindex = xlcolorindexautomatic                         end select                     next c                 next r             end         end     end end sub 

results:

    returns_business_logic


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -