+ Reply to Thread
Results 1 to 5 of 5

Macro for conditional formatting

  1. #1
    Registered User
    Join Date
    03-09-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    13

    Macro for conditional formatting

    Hi,

    I am inexperienced in VB but would like to shade cells in multiple worksheets if their value is higher than that in the cell adjacent to the left. I can do this through conditional formatting but cannot get it to work for the full workbook within a macro. The cells for possible shading are d5 : e(end of data). For example if d17 is greater in value than c17, d17 will be shaded. I have been unable to create the IF statement to identify cells to the left. Pls see my attempt below. Also this macro changes font colour rather than cell shading which would be preferable.

    Please Login or Register  to view this content.
    Thanks in advance.
    Last edited by jbyrne; 03-15-2010 at 09:13 AM. Reason: added code tags

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Macro for conditional formatting

    Edited: CODE TAGS added.
    Last edited by rwgrietveld; 03-09-2010 at 07:39 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Macro for conditional formatting

    Hi jbyrne, welcome to the forum. However, as Ricardo has already stated, your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    I'll add the tags for you this time, so our helpers are free to reply, but please remember to use code tags from now on.

  4. #4
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Macro for conditional formatting

    Hi,

    If I understood your request ... to be tested
    Sub conditshad()
    Dim i As Long
    Dim WS As Worksheet
    Dim c As Range
    i = Cells(Cells.Rows.Count, "E").End(xlUp).Row
    For Each WS In ThisWorkbook.Worksheets
    For Each c In WS.Range("D5:D" & i)
    If c.Value > c.Offset(0, 1).Value Then c.Font.ColorIndex = 3
    Next c
    Next WS
    End Sub
    HTH

  5. #5
    Registered User
    Join Date
    03-09-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Macro for conditional formatting

    Hi guys,

    Aploogies for the incorrect post. Jean that worked perfect - thanks a million.

    rgds,

    James

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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