highlite find cell?

dani1

Board Regular
Joined
Mar 23, 2010
Messages
90
hi experts!

is any body knows that if we use find option in excel so highlite found cell?

is it possible?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
hi experts!

is any body knows that if we use find option in excel so highlite found cell?

is it possible?

What do you mean by highlight the found cell ? the target cells are automatically selected as they are found and the selection highlights them .
...or do you want to change something like the found cells interior color for better visibility ?
 
Upvote 0
Try something along these lines :

(Place the code below in the worksheet module where you are performing the Find operations)

Code:
'XL 2007

Option Explicit

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private oPrevTarget As Range
Private lColIndx As Long
Private bFBold As Boolean
Private lFSize As Long

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Searching Then
        On Error Resume Next
        Call RestoreInitProps(oPrevTarget)
        Set oPrevTarget = Target
        Call StoreInitProps(oPrevTarget)
        Call HighlightRange(oPrevTarget)
    Else
        Call RestoreInitProps(oPrevTarget)
        Set oPrevTarget = Nothing
    End If

End Sub

Private Function Searching() As Boolean

    Searching = CBool(FindWindow _
    ("bosa_sdm_XL9", "Find and Replace"))

End Function

Private Sub RestoreInitProps(Target As Range)

    With Target
        If Not Target Is Nothing Then
            .Interior.ColorIndex = lColIndx
            .Font.Bold = bFBold
            .Font.Size = lFSize
        End If
    End With
    
End Sub

Private Sub StoreInitProps(Target As Range)

    With Target
        lColIndx = .Interior.ColorIndex
        bFBold = .Font.Bold
        lFSize = .Font.Size
    End With
    
End Sub

Private Sub HighlightRange(Target As Range)

    Beep
    With Target
        .Interior.ColorIndex = IIf(.Interior.ColorIndex = 3, 4, 3)
        .Font.Bold = True
        .Font.Size = .Font.Size + 4
    End With

End Sub
 
Upvote 0
thanx bro bt tell me where i ve to put dis code in module?or in sheet1 code window with wat property?
 
Upvote 0
Or try this in a standard module

Code:
Sub FindHighlight()
Dim tempcell As Range, Found As Range, sTxt, FoundRange As Range, Response As Integer
Set Found = Range("A1")
sTxt = InputBox(prompt:="Enter value for search")
If sTxt = "" Then Exit Sub
Set tempcell = Cells.Find(What:=sTxt, After:=Found, LookIn:=xlValues, lookat:=xlWhole)
If tempcell Is Nothing Then
    MsgBox prompt:="Not found"
    Exit Sub
Else
    Set Found = tempcell
    Set FoundRange = Found
End If
Do
    Set tempcell = Cells.FindNext(After:=Found)
    If Found.Row >= tempcell.Row Then Exit Do
    Set Found = tempcell
    Set FoundRange = Application.Union(FoundRange, Found)
Loop
FoundRange.Interior.ColorIndex = 6
Response = MsgBox(prompt:="Clear highlighting", Buttons:=vbOKCancel + vbQuestion)
If Response = vbOK Then FoundRange.Interior.ColorIndex = xlNone
End Sub
 
Upvote 0
Vog,

Thank you for the the above macro.

Is it possible to modify the macro so that it will highlight any cells if they contains any part of the serach value?

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top