Category / Section
How to check if a cell in a Grid is a formula cell or not?
2 mins read
The custom server has implementation to detect a formula cell with formula and value in it. IsFormulaCell is the function that provides information for a given row and column index. This function points out the formula used in that cell and the result of the formula. This returns false when the cell is not a formula cell.
The syntax
for this function is,
IsFormulaCell(row, col, formula, computedValue)
Where row is the index of the row, col is the index of the column, formula retrieves the formula of the cell, computedValue retrieves the computed or calculated value of the cell, IsFormulaCell returns true when the given row and col are a FormulaCell, false otherwise. The sample
script is as follows.
SwfWindow("GridControl").Move 592,516
SwfWindow("GridControl").SwfObject("gridControl1").SetCurrentCell 8,4
SwfWindow("GridControl").SwfObject("gridControl1").SetCellData 8,4,"40"
row = 8
IsFormula = false
formula = ""
result = ""
For col = 5 To 8
IsFormula = SwfWindow("GridControl").SwfObject("gridControl1").IsFormulaCell(row, col, formula, result)
If IsFormula Then
MsgBox ("The cell "&row &", "& col &" is a Formula Cell, with Formula "& formula&" and results "& result)
End If
Next
Note: Run the above script in the QTP server.
Sample Link: FormulaCell