The ideal setup for UIAutomation testing is to always start with the same stable start, and the test is to make sure you always end with the expected output. If your input test data is in flux, it will likely throw off your expected testable outcome.
That being said, ideal scenarios are not what we are always given. My first thought would be if you have filtering available, apply a filter to the desired value, such that there is only one possible outcome, and select that row.
If filtering is not available, my next thought would be just loop through the rows until you get to the desired row. Being you are up to 800+ rows, that may not be the best scenario.
Being there are a lot of rows, and the data is sorted, perhaps you can use a recursive searching method. There are several ways you can go about it. But one concept would be something like below.
In a nutshell, it takes in a row to start from and the total number of rows, it finds the middle value, determines if it is the cell value it is looking for, equal, greater than or less than. If it's equal, it found it's row, in the other two cases, it calls itself, adjusting the starting row and row count accordingly. I also added an additional check, to the rowcount is below a certain number, just brute force through the rows one at a time. If it finds the row, it returns it's row number, if not it returns a -1. Note the logic will need to be changed if the sort is descending.
Set Grid = SwfWindow("Form1").SwfTable("ultraGrid1")
iTest = GetRowToSelect(Grid, "name", "Name for Row#86", 0, Grid.RowCount)
If iTest <> -1 Then
Grid.SelectRow CStr(iTest)
else
msgbox "NotFound"
End If
Function GetRowToSelect(oGrid, sColName, oCellValue, iStartRow, iRowCount)
dim oCrntCellVal, iNewStartRow, iNewRowCount, iMidShift, iMidRow
If iRowCount < 6 Then
For i = iStartRow to iStartRow + iRowCount
oCrntCellVal = oGrid.GetCellData(CSTR(i), sColName)
If oCrntCellVal = oCellValue Then
GetRowToSelect = i
Exit function
End If
Next
Else
iMidShift = int(iRowCount / 2)
iMidRow = iMidShift + iStartRow
oCrntCellVal = oGrid.GetCellData(CSTR(iMidRow), sColName)
If oCrntCellVal = oCellValue Then
GetRowToSelect = iMidRow
Exit function
elseif oCrntCellVal > oCellValue Then
iNewStartRow = iStartRow
iNewRowCount = iMidShift
elseif oCrntCellVal < oCellValue Then
iNewStartRow = iMidRow + 1
iNewRowCount = iRowCount – iMidShift
End If
GetRowToSelect = GetRowToSelect(oGrid, sColName, oCellValue, iNewStartRow, iNewRowCount)
If GetRowToSelect <> -1 Then
Exit Function
End If
End If
GetRowToSelect = -1
End Function