+ Reply to Thread
Results 1 to 5 of 5

Reducing the amount of CF code in a macro.

  1. #1
    Registered User
    Join Date
    11-15-2013
    Location
    Newquay, Cornwall
    MS-Off Ver
    Excel 2010
    Posts
    67

    Reducing the amount of CF code in a macro.

    So as I am fairly new to conditional formatting, I have another question. Currently I have CF set out to highlight in BOLD all lines that contain a date withing the next 14 days.

    So I currently have the code below repeated 14 times with TODAY+1, TODAY +2, etc, etc. Is there anyway to combine this into less code?

    Please Login or Register  to view this content.
    Still learning... one day I will be able to help!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reducing the amount of CF code in a macro.

    Change the formula to this, then you only need one entry:

    =($M$2-TODAY())<15
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    11-15-2013
    Location
    Newquay, Cornwall
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Reducing the amount of CF code in a macro.

    Hmm, doesn't seem to like that. Not sure why yet. Is the syntax definitely right?

    Bracket after = and before $ correct? Do I need to remove the $ sign?

    Sorry I can't be more helpful, still learning CF.

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,426

    Re: Reducing the amount of CF code in a macro.

    What Jerry is suggesting is that your second line should read:

    Please Login or Register  to view this content.
    I've missed the $ off in front of the 2 as I suspect you want this formula to apply to rows from 2 to whatever you have selected.

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    11-15-2013
    Location
    Newquay, Cornwall
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Reducing the amount of CF code in a macro.

    Hi Pete. Yes, that's what my line looks like, I didn't replace the whole line with just that piece of code!

    So applying that to the sheet, the only date being bolded is down the bottom of the sheet, 23/12/2015. Hmmm.....

    Todays date, tomorrows date etc is still in unbolded font.

    However I have just noticed that if I manually change the date on one of the rows to within the next 14 days, it changes the cell above it to bold? Weird.

    There is one conditional statement before that in the macro to bold anything previous to todays date, perhaps that is interfering?

    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. [SOLVED] macro / code to create pivot on huge amount of data
    By Bax in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-16-2014, 03:25 AM
  2. Reducing the amount of If/and statements to give a particular result
    By grandar in forum Excel - New Users/Basics
    Replies: 13
    Last Post: 02-11-2014, 10:01 AM
  3. Replies: 5
    Last Post: 01-25-2014, 05:58 PM
  4. [SOLVED] Reducing VBA Code
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-21-2013, 07:40 AM
  5. [SOLVED] Consolidating and reducing code
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2013, 05:35 AM
  6. Tracking monthly payments and reducing the total by the amount of each payment.
    By easy365online in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-02-2012, 10:15 AM
  7. Reducing the code - applying the same code to several WorkSheets
    By kyrgyzstanart in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2008, 11:53 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