Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to search a value in excel sheet using vb script
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi All,
I have 10000 records in excel sheet, here i need to search for a paricular value in this 10000 records and if it finds a record then it has to fetch the row and coloumn of that specific value and it has to search until it reaches the 10000th record once it is finsihed then by this time i need to fetch all the row and column of the matches data

Please help me in this reagrd...

Thanks in advance,
Venkat
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Simple query repeated a 1000 times..Anyways i will give you the logic, go ahead and build your code.

1. Exploit Excel COM component (Excel.Application)
2. Set reference to the active workbook and then to the active worksheet.
3. find the total row count.
4. Use the For loop to loop through and read through the rows and cells.
5. Compare the data retrieved to match with the one you need.

Search this forum with the keyword Excel, read and build your code from the clues i have supplied.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Basanth,
Thanks for giving the logic and i implemeted and its working fine but which is taking more time to execute, can u please try to reduce the execution time

Code:
set a=Createobject("Excel.Application")
set b=a.Workbooks.open("D:\av.xls")
set c=a.worksheets("sheet1")
m=2
For i=1 to 40 step 1 'For number of rows i.e it will be searching among the first 40 rows
For j=1 to 3 step 1 ' for number of columns i.e it wil be searchinf among the first 3 columns
d=c.cells(i,j).value
If d="Tokyo" then
datatable.Value(1,1)=i
datatable.Value(2,1)=j
datatable.SetCurrentRow(m)
m=m+1
end if
Next
Next
b.close
datatable.Export("d:/av1.xls")


Please help me in this reagard,

Thanks in advance,
Venkat.
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
It is normal for it behave so. Your exploitation of the COM is one which is actually taking time. The init , execute action requires several seconds.
What is the total time taken for the execution ? Morever you havent killed the Excel object.You should do that else excel.exe wouldnt let you open another copy.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to select value from google search box dropdown +QTP prajyot 0 2,925 06-28-2017, 06:30 PM
Last Post: prajyot
  Trying to create List box in excel sheet at Run time with values yes No JACKSPARROW 0 1,736 01-17-2017, 11:05 AM
Last Post: JACKSPARROW
  Search and import data from excel under some rules. nwpulele 2 2,971 02-19-2015, 04:10 AM
Last Post: supputuri
  Excel and Driver Script shipu 1 3,863 02-27-2014, 09:09 AM
Last Post: supputuri
  Custom sort -Excel Sheet kiran 1 3,900 01-28-2014, 09:23 AM
Last Post: supputuri

Forum Jump:


Users browsing this thread: 1 Guest(s)