+ Reply to Thread
Results 1 to 9 of 9

Attempting to Highlight Cells Based on String within Cell

  1. #1
    Registered User
    Join Date
    10-16-2014
    Location
    Hamilton, Ontario
    MS-Off Ver
    2003
    Posts
    4

    Attempting to Highlight Cells Based on String within Cell

    Hello!

    Basically what I'm trying to do is the following:

    First, determine if I'm in the correct row of cells based on the String value of the cell.
    i.e If the current cell's string value contains the string AB1 or AB2, go through the entire row.

    Once that has been determined, I would like to highlight the cells either green (if the cell holds a value greater than 5) or blue (if the cell holds a value between 4 and 5).

    The above if block is not giving me trouble, it's the initial procedure.

    What is stopping me from completing this is the run-time [error '91']: "Object variable or With block variable not set".

    I do have some programming experience, I'm just having trouble with the syntax of VBA. Any help would be greatly appreciated.

    Please Login or Register  to view this content.
    Last edited by rmdlp; 10-23-2014 at 01:56 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Attempting to Highlight Cells Based on String within Cell

    The primary reason you are getting the error is because you didn't set what currCell is.

    Enable "Require Variable Declaration" to prevent this in the future.

  3. #3
    Registered User
    Join Date
    10-16-2014
    Location
    Hamilton, Ontario
    MS-Off Ver
    2003
    Posts
    4

    Re: Attempting to Highlight Cells Based on String within Cell

    Hmmm, ok! Thank you for your prompt response, I thought declaring the variable (Dim currCell As Range) would do it.

    I have currently set it to:

    Set currCell = Range("E10: AI155")


    But now I`m receiving a run-time error `1004`: Application-defined or object-defined error on the first if statement. Any suggestions?
    Last edited by rmdlp; 10-23-2014 at 02:13 PM.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Attempting to Highlight Cells Based on String within Cell

    Submit an example workbook with before and after representations on what should be highlighted blue and green.

  5. #5
    Registered User
    Join Date
    06-25-2014
    Location
    Budapest, Hungary
    MS-Off Ver
    2007
    Posts
    40

    Re: Attempting to Highlight Cells Based on String within Cell

    There you go:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-16-2014
    Location
    Hamilton, Ontario
    MS-Off Ver
    2003
    Posts
    4

    Re: Attempting to Highlight Cells Based on String within Cell

    Here are before and after workbooks as requested! Thank you again for your help.

    https://www.dropbox.com/s/9jj980pme1...efore.xls?dl=0
    https://www.dropbox.com/s/cdnckqa66q...After.xls?dl=0

    EDIT: Sorry I have the colors reversed in the workbooks.
    Last edited by rmdlp; 10-23-2014 at 02:41 PM.

  7. #7
    Registered User
    Join Date
    10-16-2014
    Location
    Hamilton, Ontario
    MS-Off Ver
    2003
    Posts
    4

    Re: Attempting to Highlight Cells Based on String within Cell

    Oh wow, thank you for your response D0se but unfortunately the code you have provided is not doing what I hoped it would do.

  8. #8
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Attempting to Highlight Cells Based on String within Cell

    Try this:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-25-2014
    Location
    Budapest, Hungary
    MS-Off Ver
    2007
    Posts
    40

    Re: Attempting to Highlight Cells Based on String within Cell

    after seeing your sample workbook heres the modded code, but please delete any empty lines on the worksheet.

    Please Login or Register  to view this content.

+ 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. Replies: 3
    Last Post: 10-01-2014, 08:00 PM
  2. [SOLVED] Count cells in row based on cell value, highlight row if wrong number or cells.
    By gutterball in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-11-2014, 04:00 PM
  3. Highlight 1 cell based on value from other cells
    By freeon in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-10-2013, 01:24 PM
  4. [SOLVED] Highlight row based on character/text string containing in cell.
    By dihris in forum Excel General
    Replies: 2
    Last Post: 12-03-2012, 11:16 AM
  5. Highlight or colour a cell or cells based on cells in another range.
    By baffld in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-30-2012, 08:41 PM

Tags for this Thread

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