Friday, October 14, 2011

How to Search for a particular value in Excel ?

Using the below script, we will be able to search a particular value in the excel file.

*******************************************************************************************

Set appExcel = CreateObject("Excel.Application")
appExcel.visible=true
 Set objWorkBook = appExcel.Workbooks.Open (filepath) 'opens the sheet

 Set objSheet = appExcel.Sheets("Sheet1)' To select particular sheet
With objSheet.UsedRange ' select the used range in particular sheet
    Set c = .Find ("nn")' data to find  
For each c in objSheet.UsedRange' Loop through the used range
 If c="nn" then' compare with the expected data
            c.Interior.ColorIndex = 40
make the gary color if it finds the data
End If
            Set c = .FindNext(c)' next search
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing

**********************************************************************************************

No comments:

Post a Comment