Friday, February 25, 2011

Perform search in Excel file

'Excel1 : D:\temp.xls            Sheet1 with two columns "Mobile" &"result"
'Excel2 : D:\temp1.xls           Sheet1 with column "Mobile"
'Search "Mobile #" present in Excel1 into Excel2
'if information is available in Excel 2 , Put the text "P" in result column of Excel1
'if information is not available in Excel 2 , Put the text "NP" in result column of Excel1
'Save temp.xls as temp2.xls
---------------------------------------------------------------------------------------

DataTable.Import "D:\temp.xls"
globalrow=DataTable.GetRowCount

Set obj=Createobject("Excel.Application")
Set objwb=obj.WorkBooks.Open("D:\temp1.xls")
Set objsheet=objwb.Sheets("Sheet1")
obj.visible="True"
flag=0

For i=1 to globalrow
   Datatable.SetCurrentRow(i)
   dev=int(DataTable("East",global))
   set foundrow=objsheet.Cells.Find(dev)
   On Error resume next
   flag=foundrow.Row

   If flag<>0Then
    DataTable.Value("result",global)="P"
    else
    DataTable.Value("result",global)="NP"
  End If
flag=0
Next

DataTable.Export "c:\temp2.xls"


Revert me back in case of query @ http://twitter.com/jaijeetpandey