Quick test professional

QTP Tips QTP codes QTP Faqs and more

Search for a particular value in Excel

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

Author:Mohan Kakarla

October 21, 2008 - Posted by quicktestprofessional | Excel Automation, Uncategorized | , , | 6 Comments

6 Comments »

  1. hey can you help me in this issue ?
    i have a batch process which runs for 8 hours .Now the developement of the application is complete .It’s in testing phase.while testing(automation testing , with any tool )can the script call the batch process in and can the script wait for results from batch process for such a long time ?

    Comment by meyya | November 24, 2008 | Reply

  2. meyya,
    yes it can wait , for that use shell object

    Dim oShell
    Set oShell = CreateObject (“WSCript.shell”)
    oShell.run “cmd /K CD C:\Documents and Settings\kmohankumar\Desktop & 2.vbs”,,true’ here true indicates wait until this step completes, if u provide false here the qtp does not wait till it completes
    Set oShell = Nothing
    msgbox “hi”

    Comment by quicktestprofessional | November 25, 2008 | Reply

  3. Hi,
    Can you please help me with a problem that I’m having with QTP? I need to loop through an excel sheet with data and create an array with required data.

    I hope you can understand my question. Please let me know if you cannot. I’ll try in a different way. Thanks.

    Comment by Sumi | March 25, 2009 | Reply

  4. Hi
    Good one
    it will be more fast if you use this

    Set appExcel = CreateObject(“Excel.Application”)
    appExcel.visible=true
    Set objWorkBook = appExcel.Workbooks.Open (filepath)
    Set objSheet = appExcel.Sheets(“Sheet1″)

    set objValueFind = objectSheet.UsedRange.Find(“rajiv”)
    If Not objValueFind Is Nothing Then
    rem find the address
    firstAddress = objValueFind.Address
    rem make the gary color if it finds the data
    objValueFind.Interior.ColorIndex = 40
    Do
    Set objValueFind = .FindNext(objValueFind)
    Loop While Not objValueFind Is Nothing And objValueFind.Address firstAddress
    End If

    Comment by rajivkumarnandvani | April 25, 2009 | Reply

  5. Hi,

    Can u please help me with this. I need to find the repeated entries also. The above code searches for a text but it colors only one again and again when multiple entries of the text are present.

    Comment by Sapna | May 28, 2009 | Reply

  6. Hello,
    I’m a new in QTP. please help me, I wants write a test case in google web page, how to I write it or what is the procedure……….
    Please help me………..

    Comment by Manish Pathak | October 5, 2009 | Reply


Leave a comment