+ Reply to Thread
Results 1 to 7 of 7

Highlighting code works but doesn't scan existing number

  1. #1
    Registered User
    Join Date
    06-05-2014
    Posts
    3

    Highlighting code works but doesn't scan existing number

    Hey Guys,

    I have a code that's job is to scan a list of numbers thats on a separate tab. Then, it is supposed to scan the rest of the workbook(10 tabs) and highlight any numbers from the list in the column C, Green. It does work, however the problem is that it only highlights the numbers in the workbook that are just entered and not pre-existing numbers. When I open the document, I need the code to scan every number and highlight the numbers in the workbook regardless of it was just entered or if it is new to the list. The code is posted below and any help would be greatly appreciated!

    THANKS!

    'if the number you input isn't in Column C, you won't get anything
    If Not Intersect(Target, Range("C2:C500")) Is Nothing Then

    'looks through OvM Jobs tab
    Dim lastrow As Long
    lastrow = Sheet14.Range("D" & Rows.Count).End(xlUp).Row

    'Must use uppercase letters in SONs'

    For Each cell In Sheet14.Range("D2:D" & lastrow & "")

    If Left(Target, 10) = Left(cell, 10) Then


    'if the job matches, turn the cell Green
    Target.Interior.Color = vbGreen
    'exit the sub so it doesn't continue looking
    Exit Sub

    End If

    Next cell
    End If

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Highlighting code works but doesn't scan existing number

    Remove the EXIT SUB after 'exit the sub so it doesn't continue looking

  3. #3
    Registered User
    Join Date
    06-05-2014
    Posts
    3

    Re: Highlighting code works but doesn't scan existing number

    Quote Originally Posted by ranman256 View Post
    Remove the EXIT SUB after 'exit the sub so it doesn't continue looking
    It didn't change anything. Thanks for the try though. Any other ideas?

  4. #4
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Highlighting code works but doesn't scan existing number

    sorry...not sure about the loop. I test.

  5. #5
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Highlighting code works but doesn't scan existing number

    I dont see where : TARGET gets assigned ( in Target.Interior.Color =..)
    It has no value.

  6. #6
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Highlighting code works but doesn't scan existing number

    The line: For Each cell In Sheet14.Range("D2:D" & lastrow )
    doesnt need the last quotes...but i dont hurt neither.

  7. #7
    Registered User
    Join Date
    06-05-2014
    Posts
    3

    Re: Highlighting code works but doesn't scan existing number

    Quote Originally Posted by ranman256 View Post
    I dont see where : TARGET gets assigned ( in Target.Interior.Color =..)
    It has no value.
    I'm sorry, I should've included the entire code and not just a portion


    Private Sub Worksheet_Change(ByVal Target As Range)

    'if the worksheet change is in the correct range, format it
    If Not Intersect(Target, Range("A2:S47")) Is Nothing Then

    Target.Font.Name = "Arial"
    Target.Font.Size = 18
    Target.Font.FontStyle = "Bold"
    Target.HorizontalAlignment = xlCenter

    With Target.Borders(xlEdgeBottom)
    .Weight = xlThick
    .LineStyle = xlContinuous
    End With
    With Target.Borders(xlEdgeTop)
    .Weight = xlThick
    .LineStyle = xlContinuous
    End With
    With Target.Borders(xlEdgeRight)
    .Weight = xlThick
    .LineStyle = xlContinuous
    End With
    With Target.Borders(xlEdgeLeft)
    .Weight = xlThick
    .LineStyle = xlContinuous
    End With
    Else:
    'do nothing
    End If


    'if the number you input isn't in Column C, you won't get anything
    If Not Intersect(Target, Range("C2:C500")) Is Nothing Then

    'looks through OvM Jobs tab
    Dim lastrow As Long
    lastrow = Sheet14.Range("D" & Rows.Count).End(xlUp).Row

    'Must use uppercase letters in SONs'

    For Each cell In Sheet14.Range("D2:D" & lastrow & "")

    If Left(Target, 10) = Left(cell, 10) Then


    'if the job matches, turn the cell Green
    Target.Interior.Color = vbGreen
    'exit the sub so it doesn't continue looking

    End If

    Next cell
    End If


    End Sub

+ 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: 11
    Last Post: 11-04-2013, 04:32 PM
  2. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  3. Cancel printing VBA code doesn't works on excel 2010
    By saesaria in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-28-2013, 06:08 AM
  4. Code that sometimes works and sometimes doesn't
    By kat14 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2013, 05:20 PM
  5. it works, it doesn work, its works....and so on.
    By Naz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-30-2005, 09:05 AM

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