+ Reply to Thread
Results 1 to 7 of 7

Conditional Formatting using VBA

  1. #1
    Registered User
    Join Date
    03-31-2012
    Location
    Nottingham
    MS-Off Ver
    OFFICE 365
    Posts
    17

    Conditional Formatting using VBA

    Morning,

    I have a spreadsheet in Excel 2003 and with conditional formatting only allowing for 3 formats I have had to resort to VBA to format individual areas of the sheet.

    I have some code which works well, but doesn't quite do what I need.

    In column R there is a calculated number. This is the number of days something has taken to be returned to me. I want my VBA to format the column J based on the corresponding cell in R.

    e.g. R5 = 60 then J5 should be red
    R6 = 35 then J6 should be orange

    The current VBA does this, but only for the cell in R - I don't know how to to change the cell to J.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Conditional Formatting using VBA

    Please Login or Register  to view this content.
    You could also use rCell.offset(0,-7) to return a cell relative to another.

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Conditional Formatting using VBA

    Try the below code….

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    03-31-2012
    Location
    Nottingham
    MS-Off Ver
    OFFICE 365
    Posts
    17

    Re: Conditional Formatting using VBA

    Thanks to all - the formulas worked well.

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Conditional Formatting using VBA

    @ SixthSense,

    I'm not sure about that code, I think union gives an error if one of the arguements is empty so if you have only formulas in your range, rMyRng will be empty after you run this code:
    Please Login or Register  to view this content.
    It would only work if you have only constants or both constants and formulas I believe.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Conditional Formatting using VBA

    @ yudlugar,

    Yes, you are 100% right and thanks for pointing it

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Conditional Formatting using VBA

    I wasn't 100% sure!

    @ OP, using Sixthsense's method, you can do this that would run quicker than my code and work for formula only instances:
    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 09-20-2013, 06:23 PM
  2. Replies: 2
    Last Post: 09-19-2013, 10:34 AM
  3. Delete Conditional Formatting conditions but keep cell formatting - Excel 2010
    By tetreama in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 08:28 PM
  4. Replies: 3
    Last Post: 05-15-2012, 04:13 PM
  5. Macro for formatting fonts and cell colours - not Conditional Formatting
    By Kayaness in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-07-2011, 03:46 AM

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