+ Reply to Thread
Results 1 to 4 of 4

Extend range of existing conditional formatting to further cells?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2017
    Location
    Munich
    MS-Off Ver
    Office 365
    Posts
    20

    Extend range of existing conditional formatting to further cells?

    Hi together,

    I established one rule for conditional formatting, and it already applies to some cells.

    I create now a macro which formats further cells; is there a way to apply exactly the same conditional formatting to these new cells? So that in the end, there is just ONE conditional formatting rule which applies to several cells, instead of several (same) conditional formatting rules, each of them applying to only one cell?

    To clarify: I want to have just one cond. format. rule in my worksheet, which applies to several cells; my question is if the range of this rule can be extended by means of a macro.

    Thanks,
    Requin

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,945

    Re: Extend range of existing conditional formatting to further cells?

    I don't think you can edit the Conditional Formatting. I suspect that you have to delete what's there and re-apply it.

    This is a recorded macro to set up CF in cell C7 to C19

    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Range("C7:C19").Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=C1="""""
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    End Sub
    And this is a macro which will loop through all the CF on a worksheet and create a list of the ranges and the formulas

    Option Explicit
    
    Sub lsform()
    Dim cf As FormatCondition
    Dim rng As Range
    
    Dim vArray, i As Long
    
    Set rng = Cells
    
    If rng.FormatConditions.Count = 0 Then
        MsgBox "No CF"
        Exit Sub
    End If
    
    ReDim vArray(1 To rng.FormatConditions.Count, 1 To 2)
    i = 0
    For Each cf In rng.FormatConditions
        'Debug.Print cf.Formula1, cf.AppliesTo.Address
        i = i + 1
        'build array of conditions and addresses
        vArray(i, 1) = cf.Formula1
        vArray(i, 2) = cf.AppliesTo.Address
    Next cf
    
    ' output array to same sheet, specified start cell
    With Range("G1").Resize(UBound(vArray, 1), 2)
        .NumberFormat = "@"
        .Value = vArray
    End With
    ' output array to another sheet, specified start cell
    With Sheet2.Range("A1").Resize(UBound(vArray, 1), 2)
        .NumberFormat = "@"
        .Value = vArray
    End With
    
    End Sub

    You can also check the interior color and the font color, etc:

    ?cf.Interior.Color
     65535 
    ?cf.Font.Color
    Null
    So, if you first establish the range, the formula, the background, font, borders, whatever, you should be able to adjust the range and re-apply the CF.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-17-2017
    Location
    Munich
    MS-Off Ver
    Office 365
    Posts
    20

    Re: Extend range of existing conditional formatting to further cells?

    Thank you for your answer! Sounds compliated, but I will give it a try...

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,945

    Re: Extend range of existing conditional formatting to further cells?

    You're welcome. Thanks for the rep.

+ 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. Can you modify the range (using a Sub) for an existing conditional formatting rule?
    By sam.schardt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-04-2016, 02:44 PM
  2. Conditional formatting for a range of cells based on data from two cells
    By Tindomerel in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-25-2014, 05:09 AM
  3. Replies: 3
    Last Post: 08-13-2013, 09:44 AM
  4. vlookups in vba to extend conditional formatting beyond 3 rules
    By wanty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2012, 10:04 PM
  5. Dynamic dates range extend to the associated cells
    By razaas in forum Excel General
    Replies: 4
    Last Post: 12-26-2011, 03:39 PM
  6. Macro to extend conditional formatting down 2 columns
    By Macca_GB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2011, 02:51 PM
  7. Excel 2007 : Extend conditional formatting
    By Almson in forum Excel General
    Replies: 5
    Last Post: 05-12-2011, 06:15 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