+ Reply to Thread
Results 1 to 8 of 8

VBA code for Conditional formating for more rows and columns and criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    11

    VBA code for Conditional formating for more rows and columns and criteria

    Hi friends, kindly help us with a VBA code for conditional formatting as mentioned in the title, attached the sample sheet for the reference, where we need to pull the colors is mentioned.

    The coding should apply in G and H column in the background.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VBA code for Conditional formating for more rows and columns and criteria

    are you looking for VB code or conditional formatting through Excel?
    ________________________________________________________
    If your problem is solved, update the thread as SOLVED: Go to the top of the first post-Select Thread Tools-Select Mark thread as Solved OR - Go to the first post - Click edit- Click Advance- Just below the word "Title:" you will see a dropdown with the word No prefix.- Change to Solve- Click Save.

    Show your gratitude to the person who helped you solving your problem by clicking on star button at the bottom of such post.

  3. #3
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VBA code for Conditional formating for more rows and columns and criteria

    If you are using Excel 2003, you can add only 3 conditions to any cell. Not more than that.

  4. #4
    Registered User
    Join Date
    09-11-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VBA code for Conditional formating for more rows and columns and criteria

    I need a VBA code and I use excel 2010

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA code for Conditional formating for more rows and columns and criteria

    FWIW:

    Sub antoanand1981()
    Dim rcell As Range
    For Each rcell In Range("I2:J" & Range("J" & Rows.count).End(3)(1).Row)
        Select Case rcell.Value
            Case Is = "G"
                rcell.offset(, -2).Interior.ColorIndex = 4
            Case Is = "Y"
                rcell.offset(, -2).Interior.ColorIndex = 6
            Case Is = "O"
                rcell.offset(, -2).Interior.ColorIndex = 44
            Case Is = "R"
                rcell.offset(, -2).Interior.ColorIndex = 3
            Case Is = "NR"
                rcell.offset(, -2).Interior.ColorIndex = 16
            Case Is = "ND", "NRW"
                rcell.offset(, -2).Interior.ColorIndex = 37
        End Select
    Next rcell
    
    End Sub

  6. #6
    Registered User
    Join Date
    09-11-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VBA code for Conditional formating for more rows and columns and criteria

    Conditional formatting.jpg Attached an image for your reference

  7. #7
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VBA code for Conditional formating for more rows and columns and criteria

    Please change the MS-Off version in your profile (showing as Excel 2003). Try the below code.
    Sub Test()
    Lastrow = Range("G" & Rows.Count).End(xlUp).Row
    With Range("G2:G" & Lastrow)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:="=I2=$M$2" 'set formatting formula
        .FormatConditions(1).Interior.Color = 5296274 'add green color
        .FormatConditions.Add Type:=xlExpression, Formula1:="=I2=$M$3" 'set 2nd formatting formula
        .FormatConditions(2).Interior.Color = 65535 'add yellow color
        .FormatConditions.Add Type:=xlExpression, Formula1:="=I2=$M$4" 'set 3rd formatting formula
        .FormatConditions(3).Interior.Color = 49407 'add orange color
        'continue for all other criteria
        'you can get the color codes on net or record a macro setting them up
    End With
    With Range("H2:H" & Lastrow)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:="=J2=$M$2" 'set formatting formula
        .FormatConditions(1).Interior.Color = 5296274 'add green color
        .FormatConditions.Add Type:=xlExpression, Formula1:="=J2=$M$3" 'set 2nd formatting formula
        .FormatConditions(2).Interior.Color = 65535 'add yellow color
        .FormatConditions.Add Type:=xlExpression, Formula1:="=J2=$M$4" 'set 3rd formatting formula
        .FormatConditions(3).Interior.Color = 49407 'add orange color
        'continue for all other criteria
        'you can get the color codes on net or record a macro setting them up
    End With
    End Sub

  8. #8
    Registered User
    Join Date
    09-11-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VBA code for Conditional formating for more rows and columns and criteria

    HI All,

    Thanks for the response, but I need the formatting done behind ma results. Check the below explanation

    VBA codes for conditional formatting which has multiple criteria. Example Column A1:A10 has names, each names has three criteria from B1:D10 and Column E has achieved result for each names... results Should fetch in Column E. So the Macro or VBA codes should check each criteria and highlight Column in different colors with the results in the front.

    Example: A1: Ramesh has achieved 98, B1:D1 = (B1=99,C1=95,D1=90), Result is 98 with Yellow background
    Formulas for example =if(E1>=B1,"Green",if(and(E1>=C1,E1<B1),"Yelow",if(and(E1>=D1,E1<C1),"Orange","Red")))
    Note :Im Using Microsoft Excel 2010.

    Please reply ASAP very Urgent.

    Hope u got it. u can also mail me at [email protected] or let me know I can call u to fix this thanks.....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel 2010- Copy Conditional Formating from a row with 4 columns to all rows
    By dudeshane01 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-22-2013, 12:45 AM
  2. Criteria Conditional Formating
    By OLLY-7 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-01-2013, 05:40 AM
  3. [SOLVED] Conditional Formating with 2 criteria
    By rizmomin in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-03-2013, 11:17 AM
  4. Conditional formating with multiple criteria
    By jlkirk in forum Excel General
    Replies: 9
    Last Post: 11-17-2010, 07:01 PM
  5. conditional formating of group of columns and rows
    By Madhav in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-08-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1