+ Reply to Thread
Results 1 to 4 of 4

Conditional Formatting through VBA

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Conditional Formatting through VBA

    Hello Team

    On worksheet name "XX",

    Data is arranged like -

    Column H has basic numeric data
    Column I used for Filter purpose
    Column J derives same value from corresponding cells in Column H using following formula
    Cell J2 =
    =SUBTOTAL(9,H2)
    Further, Column J is conditionally formatted. I manually apply following formula (because, through VBA every day, old data is deleted, Coditional formatting is lost since new data is populated).

    Please Login or Register  to view this content.
    Good if $J$500 could be changed to dynamic formula, like till last filled cell in Column J, since ROW data keeps changing, currently, filled data is upto 188 only

    How Can I do it through VBA / Macro code observing
    1) Deleteing erstwhile applied conditional formatting on entire Column J
    2) Make use of above Conditional Formatting formula, and if true, apply Conditonal Formatting
    3) Result should work, considering Excel Wrokbook is in base 2010 version.

    Sample workbook attached.
    Attached Files Attached Files
    Last edited by analystbank; 07-18-2023 at 03:29 AM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,204

    Re: Conditional Formatting through VBA

    Try

    Set "Control" as dynamic range

    =OFFSET(XX!$J$2,,,COUNTIF(XX!$J$2:$J$20000,"<>"),1)

    and change CF

    =COUNTIF(Control,"<"&$J2)<$P$1

    Applies To: =Control
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Conditional Formatting through VBA

    Hi there,

    See if the attached version of your workbook does what you need - it uses the following Defined Names:

    iMAX_ENTRIES = 500

    forNoOfEntries = =COUNTA(XX!J2:OFFSET(XX!$J$2, XX!iMAX_ENTRIES, 0))

    ptrColumn_J = =XX!$J$2:OFFSET(XX!$J$2, (XX!forNoOfEntries - 1), 0)


    The conditional formatting rules have been changed to:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.

    The conditional formatting applies to the range J2:J501 (using a dynamic named range here doesn't seem to work consistently in Excel 2016)


    Hope this helps.

    Regards,

    Greg M
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Conditional Formatting through VBA

    Thanks Brothers.

+ 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] Conditional Formatting based on another cells Conditional Formatting
    By chriskay in forum Excel General
    Replies: 4
    Last Post: 08-22-2019, 05:33 AM
  2. [SOLVED] Override conditional formatting (in general, without changing the conditional formatting)
    By Stormin' in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-21-2017, 07:15 AM
  3. Conditional Formatting Removing Previous Conditional Formatting?
    By CravingGod in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2016, 01:02 PM
  4. Replies: 6
    Last Post: 01-08-2016, 06:44 PM
  5. Opening xlsm files with conditional formatting opens with removed conditional formatting
    By Martijn.Steenbakker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2014, 05:38 AM
  6. Replies: 1
    Last Post: 09-20-2013, 06:23 PM
  7. Replies: 3
    Last Post: 05-15-2012, 04:13 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