+ Reply to Thread
Results 1 to 8 of 8

Highlight the contents using VBA or Macro.

  1. #1
    Registered User
    Join Date
    03-11-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    4

    Highlight the contents using VBA or Macro.

    Problem Statement:
    Let us say, I have following columns and their respective values.
    A3: Hello
    A4: Excel
    A5: World

    A7: =A3&A4&A5

    The output of this formula for example will be displayed in A7 as.

    HelloExcelWorld

    Now let us say, in a range of cells, there are many formula and some of them refer to contents in A7.

    For example, many cells have complex formula and within the formula they have a call to MID function like =MID (A7, 6, 5), which is the substring “Excel” from column A7.

    What I want is some way to highlight the substring “Excel” in the actual column i.e. A7.

    Contents in A7 should show Excel in Bold Blue colour, and remaining string as is.

    So, basically I need some VBA code or macros to find out what all other cells refer contents of A7 and then highlight the contents in A7, which are being referred.

    Any help in this regard is highly appreciated.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlight the contents using VBA or Macro.

    It is not possible to partially format the text result display of a formula. You can only partially format text that is flat text in a cell. Even with VBA. (or a macro, hehe)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Highlight the contents using VBA or Macro.

    Hi excelrakesh
    Try this with xl2003
    not to sure when the characters syntax was introducted
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  4. #4
    Registered User
    Join Date
    03-11-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Highlight the contents using VBA or Macro.

    First of all thanks for your replies. This is definitely possible for sure. Infact, I have seen an example in some sheet, but it was bit different.

    The main thing is I don't know what all other cells refer A7, so reply by pike will not apply as the logic mentioned by him assumes that it is already known what all cells refer A7, whereas the biggest problem I have is I don't know what cells refer A7.

    So I need 2 things, first to check which all cells refer to A7, using MID() function. And then, highlight the contents within the cell that are being used.

    Please suggest some solution.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlight the contents using VBA or Macro.

    I repeat. If the cells you are talking about contain formulas, then you cannot partially format the text displayed as a result of the formulas.

  6. #6
    Registered User
    Join Date
    03-11-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Highlight the contents using VBA or Macro.

    Thanks for your reply.

    I got your point. What I can do is copy the result of the formula in a new Cell, and then highlight contents in that cell. I am sure this is possible.

    Let us assume that the location of the cell where I copy the result of the formula is fixed. For example A9 i.e. I have pasted result of formula in A7 in A9. So I want to highlight contents in A9.

    Now, how to reach till there, assuming rest of the problem statement is same.

  7. #7
    Registered User
    Join Date
    03-11-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Highlight the contents using VBA or Macro.

    To explain and reduce the problem statement further. I want to get to the following point.

    If am able to produce following data using some logic i.e.
    Column Being referred StartPosition NumberOf characters
    A7 6 5

    Then I use this information to highlight text in A9.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Highlight the contents using VBA or Macro.

    You can use the INSTR() function in VBA to get the "position" of one string inside another.
    You can use the LEN() function in VBA to get the length of a particular string.

    The INSTR() result could be used as the "starting point" parameter.
    The LEN() result could then be used as the "number of characters" parameter.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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