Results 1 to 5 of 5

Highlight rows multiple criteria vba

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-14-2012
    Location
    Belgium/UK
    MS-Off Ver
    Excel 2003
    Posts
    111

    Highlight rows multiple criteria vba

    Hello,

    Looking for a code that highlights rows when criteria are met (or not) via a InputBox.

    e.g.: run macro, input box 1: enter premium, input box 2: enter selected. Run throw the rows and every row that has "premium" and "selected" higlights green, but if there is only 1 of the criteria in the row, highlight red.

    Attached is sample of the expected result.


    I tried changing the following code as it highlights cells but no luck.

    Sub HighlightValue()
    'PURPOSE: Highlight all cells containing a specified values
    Dim fnd As String, FirstFound As String
    Dim FoundCell As Range, rng As Range
    Dim myRange As Range, LastCell As Range
    'What value do you want to find?
      fnd = InputBox("First Value", "Find", "enter text")
         'End Macro if Cancel Button is Clicked or no Text is Entered
          If fnd = vbNullString Then Exit Sub
    Set myRange = ActiveSheet.UsedRange
    Set LastCell = myRange.Cells(myRange.Cells.Count)
    Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
    'Test to see if anything was found
      If Not FoundCell Is Nothing Then
        FirstFound = FoundCell.Address
      Else
        GoTo NothingFound
      End If
    Set rng = FoundCell
    'Loop until cycled through all unique finds
      Do Until FoundCell Is Nothing
        'Find next cell with fnd value
          Set FoundCell = myRange.FindNext(after:=FoundCell)
        'Add found cell to rng range variable
          Set rng = Union(rng, FoundCell)
        'Test to see if cycled through to first found cell
          If FoundCell.Address = FirstFound Then Exit Do
      Loop
    'Highlight Found cells yellow
      rng.Interior.Color = RGB(255, 255, 0)
    'Report Out Message
      MsgBox rng.Cells.Count & " cell(s) were found containing: " & fnd
    Exit Sub
    'Error Handler
    NothingFound:
      MsgBox "No cells containing:"
    End Sub
    Any help appreciated.

    Red
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Highlight cell for a criteria within multiple rows
    By ameeto.nike in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-02-2016, 10:34 PM
  2. [SOLVED] Highlight Duplicate Rows Based on Multiple Criteria
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-15-2013, 09:39 AM
  3. Replies: 1
    Last Post: 10-30-2012, 05:40 PM
  4. Replies: 7
    Last Post: 09-13-2011, 12:04 PM
  5. Highlight according to multiple criteria
    By Rage in forum Excel General
    Replies: 6
    Last Post: 10-04-2010, 07:11 AM
  6. Identify/highlight maximum value based on multiple criteria
    By JennB in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-06-2009, 06:28 PM
  7. match multiple criteria and highlight corresponding row in Excel
    By D Assess in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-02-2006, 12:30 PM

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