Results 1 to 7 of 7

Thread: Highlighting All the Cells of Active sheet which contains a particular String:

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member littleiitin's Avatar
    Join Date
    Aug 2011
    Posts
    90
    Rep Power
    13

    Highlighting All the Cells of Active sheet which contains a particular String:

    If You want to find any string in whole sheet then Give a try to Below Code:


    Code:
    Sub SelectXCells(strSearch As String)
    
        Dim rngWhole     As Range
        Dim rngUni      As Range
        Dim lngRow      As Long
        Dim lngCol      As Long
        Dim rngCell     As Range
        
        Set rngWhole = ActiveSheet.UsedRange
        For Each rngCell In rngWhole
            If InStr(1, rngCell, strSearch, vbTextCompare) > 0 Then
                If rngUni Is Nothing Then
                    Set rngUni = rngCell
                Else
                    Set rngUni = Union(rngUni, rngCell)
                End If
            End If
        Next rngCell
        On Error Resume Next
        rngUni.Select
        On Error GoTo 0
    End Sub
    Example:
    Code:
    Sub Test()
    
        Dim strFind As String
        
        strFind = InputBox("Please enter string to find", "Find String in Used Range")
        SelectXCells (strFind)
    End Sub
    Last edited by littleiitin; 11-27-2011 at 10:56 AM.

Similar Threads

  1. Replies: 1
    Last Post: 06-12-2013, 07:42 PM
  2. Replies: 13
    Last Post: 06-10-2013, 09:05 AM
  3. Replies: 2
    Last Post: 02-06-2013, 12:00 PM
  4. don't copy filtered data if no active cells
    By xander1981 in forum Excel Help
    Replies: 29
    Last Post: 11-01-2012, 06:47 PM
  5. Highlighting Blank Cells
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 08-13-2012, 07:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •