sql server - conditional formatting for background color using VBA? -


i got vba code populate t-sql query data in excel file. in data, 1 column contains values of red, amber, green , n/a. want background color according values (red, amber, green , white). how can in vba?

edited: need this:

id firstname lastname complaint 1  paul      nixon    red 2  john      nathon   red 3  sera      teag     amber 4  clare     walker   green 

now want background color column 'complaint' according cell value, if cell value red want background color red etc.. in vba code.

changing background color of cell simple. determining color change key step here. if know 4 colors options, pound out cases , set colors. if find growing more colors, may want define them in dictionary , lookup instead of select-case construction.

this simple code work example. want define range better (probably not "d2:d5") based on real application , tweak colors.

sub colorwithtext()      dim cell range      each cell in range("d2:d5")         select case ucase(cell.value)             case "red"                 cell.interior.color = rgb(255, 0, 0)             case "amber"                 cell.interior.color = rgb(255, 191, 0)             case "green"                 cell.interior.color = rgb(0, 255, 0)             case "white"                 cell.interior.color = rgb(255, 255, 255)         end select     next cell end sub 

here picture of excel instance after code runs. image colors applied


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -