Quality Testing

Quality is delighting customers

how to get the count of rows having same value in excel sheet in qtp


Views: 2068

Reply to This

Replies to This Discussion

Observe the following code:

dim exo,wbo,wso,r

set exo=createobject("Excel.Application") ' creating the excel object

set wbo=exo.workbooks.open("Path of the excel file") ' creating the workbook object

set wso=wbo.worksheets("Sheet Name") ' creating the worksheet object

r=wso.usedrange.rows.count ' counting the number of rows in the specified excel sheet


In variable "r" you will get the number of rows in the specified excel sheet.

in the same way you can also know the number of columns in the excel sheet:

c=wso.usedrange.columns.count ' number of columns in the specified excel sheet.



static File_Path="";#Exact Path of the Excel file
static rc,T_R_C;
#Action:Count the number of Rows in the Excel sheet

if((rc!=E_OK) && (rc!=E_FILE_OPEN))
treturn("File Not Open");
printf("\t Number of Rows in the Table is :\t" T_R_C);


Set a= CreateObject("Excel.Application")
Set b=a.workbooks.open("d:\es.xls")
Set c=b.worksheets("Sheet1")
column_count= c.usedrange.columns.count
row_count= c.usedrange.rows.count
Msgbox "No.of Columns="&column_count
Msgbox "No.of Rows="&row_count


No.of Columns=3
No.of Rows=5


You can post this question on this blog for more information (specially for QTP related doubts)

1) http://funandknowledge.blogspot.com/2009/02/qtp-script-to-get-excel...

2) http://relevantcodes.com/qtp-parameterization-with-excel/


You are giving answers for used row & column count in Excel.

Query is, In excel sheet we have 3 rows, 1st & 3rd rows have same value. how can we get row count of that rows in Excel sheet. Am i right Chandrakanth? If it is wrong analysis pls.. sorry.



TTWT Magazine





© 2022   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service