+ Reply to Thread
Results 1 to 4 of 4

Find and Highlight Multiple

  1. #1
    Registered User
    Join Date
    06-13-2017
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    2

    Find and Highlight Multiple

    I have the following code but it is only finding the final search term because it overwrites the previous. How would I would I write a second loop so that once all of the first values are highlighted it moves to the second Fnd value, and then make it salable to a long list of search terms?

    Sub HighlightCells2()

    Dim i As Long
    Dim Fnd As String
    Dim fCell As Range
    Dim ws As Worksheet

    'Values I want to find
    Fnd = "*Boston*"
    Fnd = "*OBI*"


    For Each ws In Worksheets
    With ws
    Set fCell = .Range("A1")
    For i = 1 To WorksheetFunction.CountIf(.Cells, Fnd)
    Set fCell = .Cells.find(What:=Fnd, After:=fCell, LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False)
    If fCell Is Nothing Then
    MsgBox Fnd & " not on sheet !!"
    Exit For
    Else
    With fCell
    .Interior.ColorIndex = 6
    End With
    End If
    Next i
    End With
    Next ws

    End Sub

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: Find and Highlight Multiple

    Hi jayalanbin

    How bout uploading a sample workbook for us to make use of...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    06-13-2017
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    2

    Re: Find and Highlight Multiple

    I attached a sample workbook that searches for cells with city names in them. As you can see, when you run the macro only Atlanta gets highlighted.

    Thanks,
    Jayy
    Attached Files Attached Files

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: Find and Highlight Multiple

    Give this a try:
    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. Find and highlight two opposite numbers by multiple criteria(A+B=0)
    By bumbar in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-26-2017, 02:18 AM
  2. Find & highlight multiple values from a different sheet?
    By Faugheen in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-02-2016, 09:02 AM
  3. Find and highlight two opposite numbers by multiple criteria(A+B=0)
    By Bithia in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-11-2015, 06:08 PM
  4. Quick way to find and highlight multiple rows?
    By tnovak in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-14-2014, 01:09 PM
  5. Compare, Find and Highlight Duplicates in multiple sheets
    By EvilleT in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-19-2013, 08:42 PM
  6. Replies: 8
    Last Post: 08-23-2013, 03:57 PM
  7. [SOLVED] Using Cell Find in VBA highlight multiple Row
    By evosurf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2013, 12:12 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