+ Reply to Thread
Results 1 to 7 of 7

Convert Conditional Formatting to VBA

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2010
    Posts
    34

    Convert Conditional Formatting to VBA

    I recorded a macro to get this code for conditional formatting. It works in the spreadsheet but not in VBA:
    Please Login or Register  to view this content.
    Cells L2 through L7 have formulas. Cell D7 is a formula. I need the summed values of cells L2 through L7 compared to the value of cell D7. If they total the same amount, I don't want any conditional formats set. If the totals don't match, I want conditional formatting to fill the interior of cell D7 red and change the font color to black (default is red). (This lets me know there is a calculation error somewhere in my spreadsheet).

    Any suggestions?

    Thanks, Debbie
    Last edited by dosbirn; 07-19-2013 at 04:15 PM.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Convert Conditional Formatting to VBA

    try:
    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    07-10-2013
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Convert Conditional Formatting to VBA

    Thanks, Solus, but unfortunately that gives me the same result mine did. It turns D7 cell red even though the sum of L2:L7 equals the amount in D:7. D7 should not turn red unless it meets this condition: =L2:L7<>D7

    Could the problem be because I'm trying to compare the results of the formulas instead of the actual values?

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655
    Yes. That would be the problem.

  5. #5
    Registered User
    Join Date
    07-10-2013
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Convert Conditional Formatting to VBA

    Okay, then would you know how to change this code (formula) so that it inserts the value in cell L2 instead of the formula?

    Please Login or Register  to view this content.
    Thank you for your help with this, Solus.

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Convert Conditional Formatting to VBA

    The easiest way is probably just using a helper cell, one in a column you can hide. Like:

    Please Login or Register  to view this content.
    This lets the calculation happen in one cell and then passes the value to the cell you're using your conditional formatting for.

  7. #7
    Registered User
    Join Date
    07-10-2013
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Convert Conditional Formatting to VBA

    Okay, Solus, using your suggestion, I placed a formula in (helper) cell L8, summing L2:L7. (I didn't have to remove all of the formulas in cells L2 thru L7 after all). Then I changed the cell reference in my recorded conditional format (in my original post above) from "=L2:L7<>D7" to "=L8<>D7" and now it turns cell D7 red if L8 and D7 do not equal...and it does not change it red if the totals match. So I'm good to go!

    I tried to change the cell references in the code you gave me above but I couldn't get it to work right. I'm sure it was because I wasn't changing it correctly. But at least my macro works now.

    Also, I had to keep the helper cell within my print range or the code I have for the "set print area" wouldn't select the correct range to print.

    Thanks SO MUCH for your help, Solus!

+ 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. Convert Formula for Conditional Formatting
    By Filibuster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2013, 04:53 PM
  2. 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
  3. Replies: 3
    Last Post: 05-15-2012, 04:13 PM
  4. Replies: 2
    Last Post: 11-02-2007, 12:03 PM
  5. Convert Conditional Formatting
    By Jivo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-19-2007, 11:02 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