+ Reply to Thread
Results 1 to 18 of 18

conditional formatting varios named cells

Hybrid View

  1. #1
    Registered User
    Join Date
    04-22-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    22

    conditional formatting varios named cells

    Hello everybody,
    I 've been goggling and searching in this forum the topic of conditional formatting and named ranges but I can't find the solution to the following:
    I am writing a questionnaire (in a sheet called "Questionnaire") and have range-named various cells. They are located all over the sheet (for example D16 is named "origin_city", F21 "actual_profession", E46 "diplomas" etc..)
    Those cells are named because I'm using their values to copy them in a sheet called "Summary".
    Since the named cells are spread all over the Questionnaire sheet, each time I want to conditionally format them, I have to select each concerned cell in the "apply to" field of the conditional formatting window.

    I would want to apply the conditional formatting without having to manually select each named cell and ensure that the conditional formatting apply to ALL the named cells in the sheet.
    is this feasible via a formula, or using vba?
    Probably there is an easy solution but I'm not expert.
    thank you for your help!

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: conditional formatting varios named cells

    The only way (that I know of), to apply CF without resorting to VBA, is to actually select the cell you need to apply the CF to (or, when you select a range)

    I just tried to use a named range in CF and it did not work, so I think you are stuck with either doing each manually, or format copying, then adjusting
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: conditional formatting varios named cells

    CF appears very flexible on the surface but whenever you try to do anything outside the obvious box it quickly becomes either impossible or so complicated that it is often not worth the effort

    What condition are you applying to these cells?
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Registered User
    Join Date
    04-22-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    22
    Quote Originally Posted by kev_ View Post
    CF appears very flexible on the surface but whenever you try to do anything outside the obvious box it quickly becomes either impossible or so complicated that it is often not worth the effort

    What condition are you applying to these cells?
    Sorry for late reply. I just want to change the color and the border lines so the users know that such fields will appear in the sheet summary. can this be done with vba?
    Last edited by missbogota; 03-02-2017 at 01:20 PM.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: conditional formatting varios named cells

    But that is not a conditional format - that is just a style change.
    2 easy ways to do this
    either
    - by vba
    or
    - create a new style in Excel and then you can just click on the style icon each time

    Are the formats of these cells EXACTLY the same?

  6. #6
    Registered User
    Join Date
    04-22-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    22
    Sorry, i am lost😯. For me Conditional formating is, that when a cell complies with a certain condition, then something is applied to it (color or other characteristics) so in my case the condition is that if the cell is named then it should be colored.
    So all cells that are a named range should be colored in blue. Some of them are numeroc, others are text an the color should be appied independently of the fact that they be empty or not.
    Last edited by missbogota; 03-02-2017 at 01:40 PM.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: conditional formatting varios named cells

    Unfortunately , in using the word "Conditional", Microsoft chose to use a word that has a much wider in meaning to us than it does to Excel - that was not very helpful.

    In the attached workbook I have created a new style called "Kev" (with borders and fill), as illustrated below.

    Format any cells quickly by clicking on each cell in turn and then click on style "Kev"
    If you hold the {CTRL} key down after selecting the first cell you can select more cells and format them all together with one click.

    The fact that the cells are named is of no consequence to this solution

    The next post will include a VBA solution which can use the named ranges

    CellNewStyle1.jpg

    CellNewStyle2.jpg

    CellNewStyle3.jpg
    Attached Files Attached Files
    Last edited by kev_; 03-02-2017 at 06:28 PM.

  8. #8
    Registered User
    Join Date
    04-22-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    22
    Thanks for the hint with the styles. I still have to select each cell, though. But it's easier than ysing the conditional formatting.
    The vba option you mention is not there?

  9. #9
    Forum Contributor
    Join Date
    05-06-2016
    Location
    Cluj, Romania
    MS-Off Ver
    2007-2010
    Posts
    220

    Re: conditional formatting varios named cells

    Hi,
    Why not define a name that includes all the other names? Then just select that name

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: conditional formatting varios named cells

    @TudyBTH
    Can you explain
    - how to create a combined range and
    - how to then apply formatting to it

    thanks
    Last edited by kev_; 03-03-2017 at 04:48 AM.

  11. #11
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: conditional formatting varios named cells

    Perhaps the following link might help you http://datapigtechnologies.com/blog/...ranges-part-1/

    It seems to be doing what you want, or close to it

  12. #12
    Forum Contributor
    Join Date
    05-06-2016
    Location
    Cluj, Romania
    MS-Off Ver
    2007-2010
    Posts
    220

    Re: conditional formatting varios named cells

    Hi,
    Just select all the cells (hold down the Ctrl key) and define a name.
    Capture1.JPG
    Then select this name
    Capture2.JPG
    and apply your CF
    Capture3.JPG

  13. #13
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: conditional formatting varios named cells

    @TudyBTH
    But all defined names should has the same size, probably. I tested it a little and it works. Of course after you define all and close CF, and next open it again, names are showing as ranges.
    This is faster than select every range independently one by one.

    correction: can be different sizes
    Last edited by sandy666; 03-03-2017 at 05:29 AM.

  14. #14
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: conditional formatting varios named cells

    and a vba solution
    Run macro in attached workbook with {CTRL} {t}


    Sub formatNamedRanges()
    'declare variables
        Dim n As Name, aSheet As String, aName As String
    'loop through all names
        For Each n In ThisWorkbook.Names
        
        aSheet = n.RefersToRange.Parent.Name
        aName = n.Name
    'apply formatting
        With Sheets(aSheet).Range(aName)
                With .Borders(xlEdgeLeft)
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .TintAndShade = 0
                .Weight = xlThick
                End With
                With .Borders(xlEdgeTop)
                    .LineStyle = xlContinuous
                    .ColorIndex = xlAutomatic
                    .TintAndShade = 0
                    .Weight = xlThick
                End With
                With .Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .ColorIndex = xlAutomatic
                    .TintAndShade = 0
                    .Weight = xlThick
                End With
                With .Borders(xlEdgeRight)
                    .LineStyle = xlContinuous
                    .ColorIndex = xlAutomatic
                    .TintAndShade = 0
                    .Weight = xlThick
                End With
                With .Interior
                    .Pattern = xlSolid
                    .PatternColorIndex = xlAutomatic
                    .ThemeColor = xlThemeColorAccent6
                    .TintAndShade = 0.399945066682943
                    .PatternTintAndShade = 0
                End With
        End With
    Next n
    
    End Sub
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    05-06-2016
    Location
    Cluj, Romania
    MS-Off Ver
    2007-2010
    Posts
    220

    Re: conditional formatting varios named cells

    Question:
    Why should you change the rules of conditional formatting frequently?

  16. #16
    Registered User
    Join Date
    04-22-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    22

    Re: conditional formatting varios named cells

    The initial problem was to avoid manually changing the style to all named ranges or applying the style to new named ranges.
    Thanks @kev_ . the vba solution does exactly what I need.

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: conditional formatting varios named cells

    And if you have already created a style as indicated in post#7

    the VBA is reduced to this:

    Sub formatNamedRanges1()
    
    'declare variables
        Dim n As Name, aSheet As String, aName As String
    'loop through all names
        For Each n In ThisWorkbook.Names
            aSheet = n.RefersToRange.Parent.Name
            aName = n.Name
    'apply formatting
            Sheets(aSheet).Range(aName).Style = "Kev"
        Next n
    
    End Sub

  18. #18
    Registered User
    Join Date
    04-22-2016
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    22

    Re: conditional formatting varios named cells

    The initial problem was to avoid manually changing the style to all named ranges or applying the style to new named ranges.
    Thanks @kev_ . the vba solution does exactly what I need.

+ 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 Using a named range
    By gaker10 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-18-2014, 08:11 AM
  2. Conditional Formatting using Named Range
    By pcm1969 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-25-2013, 01:13 PM
  3. Conditional formatting using named ranges.
    By Turtleman10 in forum Excel General
    Replies: 0
    Last Post: 05-16-2013, 08:57 AM
  4. [SOLVED] Conditional formatting with named ranges, need help!
    By petelomax in forum Excel General
    Replies: 2
    Last Post: 04-27-2012, 06:30 AM
  5. [SOLVED] Conditional Formatting with Named Ranges
    By Revverend in forum Excel General
    Replies: 7
    Last Post: 04-02-2012, 05:31 AM
  6. Named range using conditional formatting
    By derekvho@gmail.com in forum Excel General
    Replies: 13
    Last Post: 04-10-2006, 06:10 PM
  7. named range, conditional formatting
    By drabbacs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-17-2005, 02:06 PM

Tags for this Thread

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