Micro Focus QTP (UFT) Forums
Getting cell number from excel sheet - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Getting cell number from excel sheet (/Thread-Getting-cell-number-from-excel-sheet)



Getting cell number from excel sheet - qtpbegin - 07-23-2012

Hi

I am writing a QTPScript(vbscript) to get cell information from excel sheet.I am able to create excel object,sheet etc.

There is a cell in sheet(1) which conatins a string "Result".How will I get this cell number using excel object?


RE: Getting cell number from excel sheet - Tarik Sheth - 07-23-2012

hi,

You can use following code. You can also iterate for all the columns as well

row
Code:
rowCount= DataTable.Getsheet("Global").RowCount
For i = 1 to rowCount
        DataTable.GetSheet("Global").SetCurrentRow i        
        If    DataTable.Value(<Column Name>, "Global") = "Result" Then
                                      MsgBox Found
                          end If

You mean cell number.
ok on top of what I have mentioned above you can use the following statement to find the Cell Value.

Code:
cellValue=workSheets("1").range(<your range of columns>.Value
range of the column could be ($P$1) like that.


RE: Getting cell number from excel sheet - qtpbegin - 07-24-2012

Thanks for the reply

But I should know the column name for this.I dont know that....Without that I need the cell number.


RE: Getting cell number from excel sheet - ssvali - 07-27-2012

Try this code

Code:
Set ObjExcel = CreateObject("Excel.Application")
ObjExcel.visible = TRUE
Set sWorkbook = ObjExcel.Workbooks.Open("z:\Sample1.xls")
Set sWorksheet = sWorkbook.Worksheets("Sheet1")

rCnt = sWorkbook.Worksheets("Sheet1").UsedRange.Rows.Count
cCnt = sWorkbook.Worksheets("Sheet1").UsedRange.Columns.Count
For i = 1 to rCnt

    For j = 1 to cCnt

        cValue = sWorkbook.Worksheets("Sheet1").Cells(i,j).Value
        If cValue = "Result" Then
            Print "Row Number - " & i & "  Column Number " & j
        End If

    Next

Next