+ Reply to Thread
Results 1 to 9 of 9

How to check whether the format of one cell is the same as another?

  1. #1
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    How to check whether the format of one cell is the same as another?

    BACKGROUND: I have implemented pseudo-conditional formatting code, where a few conditions are checked and then if met, it will copy the format of a reference cell. The end effect is that conditional formatting appears to be in effect. The reason I don't want to just use conditional formatting, is because with conditional formatting, undo becomes very slow.

    PROBLEM: when copying and pasting format on all cells of a worksheet, this can be slow. But you can avoid copying and pasting formats, if the format is exactly the same between the reference cell and the cell in question. Question: how to compare if the format between 2 cells is the same or not?

    I know you can do:
    if WS.Cells(row, col).interior.color = RWS.Cells(rrow, rcol).interior.color then...

    but that only checks the interior.color, but doesn't check font.color, it doesn't check font style etc. Rather than do a whole bunch of individual if..then.. statements, is there a way to check if ALL formats between 2 cells are the same?

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    422

    Re: How to check whether the format of one cell is the same as another?

    I'm pretty sure the answer is no. Can you describe in more detail how undo becomes very slow with conditional formatting? Is it a particularly large workbook, lots of calculations, etc...?

  3. #3
    Registered User
    Join Date
    03-01-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: How to check whether the format of one cell is the same as another?

    @superlative, Let me know if this helps you. first you need to decide that which all formatting you want to match as there are n number of formatting options available. You prepare a list of formats which you want to compare for cell and which will have impact on end result. Once you decide that you can use the "Display format property to compare the formatting of source and target cells. Below are few examples.

    ?activecell.DisplayFormat.Interior.Color
    ?activecell.DisplayFormat.Font.FontStyle
    ?activecell.DisplayFormat.Font.Color
    ?activecell.DisplayFormat.Style
    ?activecell.DisplayFormat.HorizontalAlignment
    ?activecell.DisplayFormat.WrapText
    ?activecell.DisplayFormat.Orientation

  4. #4
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: How to check whether the format of one cell is the same as another?

    Quote Originally Posted by mgs73 View Post
    I'm pretty sure the answer is no. Can you describe in more detail how undo becomes very slow with conditional formatting? Is it a particularly large workbook, lots of calculations, etc...?
    I have a worksheet where many cells had about 6 different conditional formats each. Undoing any action on them took over 5 minutes, and often just crashed the app - this is a known issue, look it up. I solved this by creating a template worksheet with formats for different cells, and then using VBA to determine which cell to copy format. This was as quick as just using conditional formatting, and made undo as quick as you would expect it to. The only time this is slow is if you want to refresh the format of the entire worksheet, and would therefore have to copy format on every cell in the worksheet - which is slow, and unnecessary if the format didn't need refreshing.

  5. #5
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: How to check whether the format of one cell is the same as another?

    Quote Originally Posted by vshukla View Post
    @superlative, Let me know if this helps you. first you need to decide that which all formatting you want to match as there are n number of formatting options available. You prepare a list of formats which you want to compare for cell and which will have impact on end result. Once you decide that you can use the "Display format property to compare the formatting of source and target cells. Below are few examples.

    ?activecell.DisplayFormat.Interior.Color
    ?activecell.DisplayFormat.Font.FontStyle
    ?activecell.DisplayFormat.Font.Color
    ?activecell.DisplayFormat.Style
    ?activecell.DisplayFormat.HorizontalAlignment
    ?activecell.DisplayFormat.WrapText
    ?activecell.DisplayFormat.Orientation
    it helps me in that you've listed all of them, but it doesn't help me in that it emphasizes my problem. As mentioned in the post before this, I have a template worksheet, which allows users to modify the appearance of the main worksheet. I allow them to change whatever format they want.

    I have a row, which is a "highlighted row" in the template. When the user filters rows, the row becomes highlighted in the main worksheet, because VBA will copy cells from this highlighted row in the template. However, the user is free to determine the format of this "highlighted row" in the template (eg. make the highlight green, or font bold, or font red).

    Therefore when the user selects to highlight all rows, or un-highlight all rows in the main worksheet, this is slow because I am applying the copy/paste format on all rows - rather than JUST the rows that have incorrect format.

    So in order to check if each cell has a different format than the reference cell, I would have to do if.. then statements on all 7 of those different formats on all cells. I was hoping there was a way to just check ONCE "if cell A has exactly the same format as cell B, then..."
    Last edited by superlative; 07-30-2019 at 10:55 AM.

  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,459

    Re: How to check whether the format of one cell is the same as another?

    Administrative Note:

    Please don't quote entire posts unnecessarily. They are just clutter and make threads hard to read.If you answer is out of sequence, perhaps add the name of the poster you are answering to
    Use the "Quick reply" instead
    Thanks

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to check whether the format of one cell is the same as another?

    There is no "check all format" method in Excel VBA.

    One work-around to speed things up is to designate one cell a the representative of a bunch of others.
    For example, if you want to know if a range of cells has the same format as a KeyCell, you could check the top left cell of the range and act as if all the others in the range have the same format as that.

    or

    you could look down the first column of the Range and decide that a cell in that column is representative for the other cells in that row.

    I'm curious about your reason for this. "because with conditional formatting, undo becomes very slow." If you are coloring cells with code, UnDo goes away (unless you write your own), so the pseudo-CF approach doesn't speed up the UnDo. I haven't noticed any time hit to UnDo with ConditionalFormatting.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: How to check whether the format of one cell is the same as another?

    Update: I created code to check every one of those 7 formats, it finished quicker than expected, so I'm happy with the performance. Here's the code:

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: How to check whether the format of one cell is the same as another?

    Quote Originally Posted by mikerickson View Post
    There is no "check all format" method in Excel VBA.

    ...
    FYI, I have code that controls cut, paste, drag and drop, insert, delete, clear contents. As far as I know, the only way to control some of these is to make use of undo. Eg. if you drag and drop something into a cell but want to swap a drag and drop overwrite with a drag and drop insert, then you have to detect the drag and drop overwrite, undo it, and then replace it with a drag and drop insert. Undoing a drag and drop over a bunch of cells that each have 6 conditional formats crashes the system.

    It's a known issue - please look it up.
    https://answers.microsoft.com/en-us/...9-7a3c38af5fcb

    Good suggestion on a possible workaround. I was just thinking that I could also have a hidden column that contains the row # of the template worksheet that contains the format of the row of the main worksheet.
    Last edited by superlative; 07-30-2019 at 11:22 AM.

+ 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. Check Cell Format across the range
    By vt1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-29-2015, 12:10 PM
  2. [SOLVED] check if number in once cell exists in a range of cells and if yes, format another cell
    By beaujolais44 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-16-2013, 07:23 AM
  3. Replies: 1
    Last Post: 04-11-2013, 01:49 PM
  4. [SOLVED] Check IF a cell is a certain DATE format?
    By biddum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-31-2012, 04:18 AM
  5. How To Check What type of Format the cell is Using VB.Net
    By pavel3002 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2011, 06:26 PM
  6. [SOLVED] Get data from Excel-cell and check format
    By SamanthaK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2006, 04:10 AM
  7. Cell Format Check
    By Rich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-17-2006, 12:00 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