简体   繁体   中英

Conditional Formatting a Row based on a Cell value using VAB

I am working on a speadsheet that takes the tasks that everyone is doing and pioritises them and i am having difficalty formatting the rows as word 2003 only lets you do three formats and i ahve alreday used them up! I would like to format the rows like so;

If the number in cell C## is 1 the Row tuns Red, if its 2 it turns orange, if it is 3 it turns yellow, if its 4 it turns light green and if its 5 it turns dark green.

Also if cell F## is Yes then the colour of the righing goes gray and the writing is crossed out.

Finally if the date in cell D## is overdue then the whole rows writting goes BOLD.

I know it can be done easily on excel 2010 but we havent upgraded yet at work.

Can awayone help?

Thanks.

here is a quick start you can elaborate on;

type ALT+F11; the VBA editor will appear, locate your sheet in the left side panel (if panel is not there type CTRL+R) double click your sheet and its module will show in the right panel

copy and paste the following code:

Sub update_color_codes()


    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    numrow = Selection.Rows.Count

    For r = 1 To numrow

    c = Cells(r, 3).Value

    Select Case c

           Case 1
           pickedcolor = RGB(0, 255, 0)
           Case 2
           pickedcolor = RGB(0, 125, 0)
           Case 3
           pickedcolor = RGB(255, 255, 0)
           Case 4
           pickedcolor = RGB(125, 125, 0)
           Case 5
           pickedcolor = RGB(255, 0, 0)


    End Select 'c


    With Range(Cells(r, 1), Cells(r, 6)).Interior
        .Pattern = xlSolid
        .Color = pickedcolor
    End With



    Next 'r = 1 To numrow



End Sub

To run this macros, type ALT+F8, select it in the list and click RUN.

to ease the process, create a keyboard shortcut like this: type ALT+F8, select it in the list and click OPTIONS, enter your shortcut key (i recommend something that will not interfere with default shortcut such as CTRL+SHIFT+U)

assumption is made your list starts on A1 and has 6 columns, correct as needed; the number of rows is found out at the beginning by the macro;

play with the RGB values until satisfied and explore VBA to adjust this code to control font weight etc.

hope that help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM