Results 1 to 9 of 9

Attempting to Highlight Cells Based on String within Cell

Threaded View

  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.

    Sub ChangeCellColor()
    
    
    
    Dim columnD As Range
    Dim str1, str2 As String
    Dim currCell As Range
    Dim rightCell As Range
    Dim i As Long
    
    
    str1 = "AB1"
    str2 = "AB2"
    
    
    Columns(1).Font.Color = vbBlack
    
    
    For i = 1 To Rows.Count
    
    
    'If the current cell in the D column contains either the string AB1 or AB2, it will look into the values here.
    If (currCell.Cells(i, 4).Value = str1) Or (currCell.Cells(i, 4).Value = str2) Then
        'From the cell range of
        For j = 1 To Range("E10").End(xlToRight)
                If rightCell.Cells(j, 5) >= 5# Then
                    rightCell.Interior.Color = vbRed
                ElseIf (rightCell.Cells(j, 5) >= 4 And rightCell.Cells(j, 5) <= 4.99) Then
                    cell.Interior.Color = vbYellow
                End If
        Next j
        
    End If
    Next i
    
    
    
    
    End Sub
    Last edited by rmdlp; 10-23-2014 at 01:56 PM.

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