+ Reply to Thread
Results 1 to 18 of 18

Exact comparison including bold / italics / underline

  1. #1
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Exact comparison including bold / italics / underline

    I have a variable number of words in each cell of two highlighted Columns. For each row I need to highlight the corresponding cells with either Green or Red depending on whether the two cells do or do not match the following criteria:

    1. The text is exactly the same including upper- or lower-case
    2. Intervening number of spaces between corresponding words in both cells is the same
    3. Each corresponding word in the two cells has the same formatting for Italics/Bold/Underline (Color/Font do not matter)

    I guess this will require some VB Code. Any help will be appreciated.

    Thanks

  2. #2
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Exact comparison including bold / italics / underline

    I just put some code together for you to get a feeling what you can do.
    Not the most beautiful, but it gets it done.....

    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Exact comparison including bold / italics / underline

    Are you always comparing the entire cells? #1 & 2 can be done with the EXACT function, but #3 means you have to use VBA.

    This user-defined function installed to a Module will return TRUE if an only if the two cells have exactly the same text and italic/bold/underline formatting. If the ranges provided contain more than one cell, only the upper-left cell will be considered.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Exact comparison including bold / italics / underline

    I should add that my version does not solve your entire problem, it just tells you whether the two cells match. Personally I would use conditional formatting to highlight the cells based on a call to FORMATMATCH.


    G e r a r d has a complete solution, although I would simplify the code as shown. First, note that comparison of two strings in VBA will always be case-sensitive, unlike comparison in an Excel sheet. Therefore there is no need for a character-by-character comparison. Also the logic can be simplified to be similar to the function I provided above. Note that I have assumed that the data starts in column A, and you are comparing to the next column to the right. That may need a little adjustment if your situation is different.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Re: Exact comparison including bold / italics / underline

    I am surely missing something here because I am getting TRUE even if A1 contains capital A and B1 contains capital A Bold and/or italicized and/or Underscored. Please see attached file. Thanks.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Exact comparison including bold / italics / underline

    Range("A1")???
    Remove that
    Please Login or Register  to view this content.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Exact comparison including bold / italics / underline

    Range("A1") returns the upper left cell of the parent. This is added in case the user passes in a range with more than one cell. I tested that code successfully before posting.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Exact comparison including bold / italics / underline

    Quote Originally Posted by qjawaid View Post
    I am surely missing something here because I am getting TRUE even if A1 contains capital A and B1 contains capital A Bold and/or italicized and/or Underscored. Please see attached file.
    That is not what I'm seeing when I open your file. Everything looks correct to me. Normally I don't post images but here is what I see.
    Attached Images Attached Images

  9. #9
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Re: Exact comparison including bold / italics / underline

    Quote Originally Posted by 6StringJazzer View Post
    That is not what I'm seeing when I open your file. Everything looks correct to me. Normally I don't post images but here is what I see.
    This is strange!Could it be that you might be using Excel 2007 while mine is 2003? I assume Gerard is seeing what I see. Can Gerard please confirm?

    Gerrad's change of removing Range("A1") solved the original issue however now if the contents are mixed italics/non italics I get a #VALUE error!
    Last edited by qjawaid; 01-29-2014 at 12:41 PM.

  10. #10
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Exact comparison including bold / italics / underline

    Quote Originally Posted by qjawaid View Post
    This is strange!Could it be that you might be using Excel 2007 while mine is 2003? I assume Gerard is seeing what I see. Can Gerard please confirm?

    Gerrad's change of removing Range("A1") solved the original issue however now if the contents are mixed italics/non italics I get a #VALUE error!
    The code works for me.
    Seeing the same as 6StrinJazzer.
    Gerard

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Exact comparison including bold / italics / underline

    Quote Originally Posted by qjawaid View Post
    Could it be that you might be using Excel 2007 while mine is 2003?
    I suppose that is possible but that is usually an issue only with built-in functions, not VBA. My VBA is not using any unusual functions or features that were not available in Excel 2003. (I am using 2010 and 2013.)

  12. #12
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Re: Exact comparison including bold / italics / underline

    Quote Originally Posted by G e r a r d View Post
    The code works for me.
    Seeing the same as 6StrinJazzer.
    Gerard
    The only difference I can see is that both you and 6StringJazzer are using Office 2010/2013 while mine is 2003. I wonder if someone can test it out with 2003.

  13. #13
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Re: Exact comparison including bold / italics / underline

    Hi,

    The code is working when two cells (the entire cells) are formatted as either Italics/Bold/Underlined, however, I need the function to be able to look within the cell and scan it word by word to see if every single word and character has matching formatting. Here is some sample data and the expected outcome from the function that I would want to see in the "Match?" column:

    Column A Column B Match?
    Hi how are you? Hi how are you? FALSE
    New York City New york City FALSE
    Warner Brothers Studios Warner Brothers Studios TRUE
    Red Robin Red RoBin FALSE
    White House White House FALSE
    New Jersey State New Jersey State TRUE
    New Jersey State New Jersey State FALSE
    United States of America United States of America FALSE

    Sorry if I wasn't clear to begin with, but this is the type of data I'm dealing with, I've thrown some case sensitivity in as well so hope that doesn't complicate it too much. For any scenarios such as the ones above the FormatMatch function is currently giving me a #VALUE! error, it is only giving true or false when the entire cells are formatted the same or differently.

    Thanks again for your help guys, I appreciate it!
    Last edited by qjawaid; 01-30-2014 at 11:27 AM.

  14. #14
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Exact comparison including bold / italics / underline

    I thought Excel was made to calculate and Word was for text.
    So, perhaps, it's easier to do something in Word (and VBA of Word).
    It's only a guess.
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  15. #15
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Exact comparison including bold / italics / underline

    OK that explains some...

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Re: Exact comparison including bold / italics / underline

    Thanks so much for the quick reply...this version of the function almost satisfies all of my needs, however, it is throwing the two cells below as FALSE when they should be TRUE as they are matching. So it seems that any cells which are identical but have mixed formatting (some words or text italicized and some that are normal), are resulting in an error which is giving the FALSE output.
    Column A Column B Match?
    Warner Brothers Studios Warner Brothers Studios TRUE

    Really appreciate all of your help Gerard!

  17. #17
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Exact comparison including bold / italics / underline

    OK, i think I found a sollution:

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    10-02-2013
    Location
    Mississauga, Ontario
    MS-Off Ver
    Office 365 Version 1909 (Build 12026.20264)
    Posts
    12

    Re: Exact comparison including bold / italics / underline

    This is great, it seems to be working perfectly. Thank you so much for all your time and help!

+ 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. Populated cell does not copy font style (italics, bold, etc)
    By ten10thmuse in forum Excel General
    Replies: 3
    Last Post: 01-29-2014, 04:55 PM
  2. Formula That Recognizes Bold or Underline
    By par5nto in forum Excel General
    Replies: 3
    Last Post: 10-24-2011, 09:20 AM
  3. Bold, Underline and Italic greyed out
    By drgogo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-08-2009, 09:30 AM
  4. Replies: 2
    Last Post: 02-28-2008, 01:45 PM
  5. bold italics or underline
    By Dorothy in forum Excel General
    Replies: 5
    Last Post: 02-16-2005, 11:28 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