+ Reply to Thread
Results 1 to 6 of 6

How to find a string and change it's color?

  1. #1
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    How to find a string and change it's color?

    Can anyone tell me which command would find a certain word in a range, then change it's color please?

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,445

    Re: How to find a string and change it's color?

    Hi,

    Try this:

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: How to find a string and change it's color?

    Thanks sweep! That looks like it should work, but I'm getting an error
    when I try it (with some adjustments to fit the code I'm trying out here.) :

    Please Login or Register  to view this content.
    I'm getting the error: "Object variable or With block variable not set" on the line: rCell = Cells(lRow, 1).Value.

    If I Dim rCell as a variant, I get the error "Object required" on the line:
    "If InStr(rCell.Value, finder) > 0 Then"

    Am I making some glaring mistake somewhere here please?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: How to find a string and change it's color?

    rCell is a range object and requires the Set command to make the assignment

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor
    Join Date
    01-13-2009
    Location
    Mumbai
    MS-Off Ver
    Excel 2003, 2007
    Posts
    168

    Re: How to find a string and change it's color?

    Hi,

    The mistake that you are making is that you are declaring rCell as range and then you are using it as a string..

    Try this code instead

    Please Login or Register  to view this content.
    HTH,
    Vaibhav
    Last edited by c.vaibhav; 05-13-2009 at 02:30 AM.

  6. #6
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: How to find a string and change it's color?

    Thanks for that guys! Works fine now
    I assume btw that it will work similarly if I make 'finder' an
    array of values, so I can change the color of multiple words using
    this code? (I'm doing this as an exercise to color my code before
    printing it out.) I'll test that out later anyway as it's nearly
    midnight here now

+ 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