+ Reply to Thread
Results 1 to 8 of 8

How do I change the font color of an InStr search result ?

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    How do I change the font color of an InStr search result ?

    I have a functioning sub that searches a column for a string and colors the first found string in each cell red.
    I would like to modify this sub so that it colors instead of the just the first found string in one cell all matched strings in the cell.

    To illustrate:
    Current: My house is yellow. My car is also yellow.
    Goal:    My house is yellow. My car is also yellow.

    How do I need to change the sub below:

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How do I change the font color of an InStr search result ?

    You are using instr, so you will only find the 1st one, you need to loop the instr, changing the 1 to be the previous instr+length

    so say chars 4 to 8 are to be higlighted, you need to do another instr from 9 onwards

    You can do this using a do while loop

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I change the font color of an InStr search result ?

    I got the concept. How do I get the position of the found string? I need it to adjust the intStartPoint.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How do I change the font color of an InStr search result ?

    That is what instr does, so you'll need instr + length

    Do you understand the code you posted?

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I change the font color of an InStr search result ?

    Yes, I understand the code I posted. I modified it from a code I found online and used it successfully. Excelforum crashed while I was working on the initial question. So, I had to google for an answer. It was after that that I realized that only the first found string is colored. I have used InStr a lot but wasn't aware that it finds the location of the string. I found out by using MsgBox just before I got your response to my followup question. Thanks for your help. I can finish the sub now.

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How do I change the font color of an InStr search result ?

    No worries, Instr means In String.

    Glad to help.

  7. #7
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: How do I change the font color of an InStr search result ?

    I know that InStr means In String. I have been using InStr for years but never bothered to find out what the output of InStr is. I always used InStr to get a yes/no answer (if Instr > 0). I assumed that the output is the number of identified strings. Since today I know that this is not the case. Thanks gain for your help. I learned a couple new things.

    Below the final answer to my questions:

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How do I change the font color of an InStr search result ?

    Glad to be of help.

    Enjoy your knowledge

+ 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] keyword search - a macros to change font color for specific key words (not entire cell)
    By kingwhopper in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2014, 12:25 PM
  2. Change font color of specific text as a result of an if statement
    By Triscia in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-07-2013, 11:47 AM
  3. Replies: 2
    Last Post: 04-27-2006, 01:46 PM
  4. [SOLVED] change font color on search
    By frogtoad123 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-28-2005, 01:50 PM
  5. [SOLVED] Search for text, change font color
    By John in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2005, 11:05 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