title: SAP GUI scripting - Gridview - Find text in a given column and doubleclick the cell
body: <p>I m using excel VBA to try and automate some SAP data entry.</p>
  
  <p>I have a gridview control that I m trying to find specific text in a column, then double-clicked that cell to select it.</p>
  
  <p>I m currently using a for loop to find the row but getting some strange result. When I step through the code, I can get to the row but cannot select or double-click it. When the code runs at the usual speed, the row is not even selected!</p>
  
  <p>Is there a better way to go about this?</p>
  
  <p>This is the code is have so far</p>
  
  <pre><code> Function SelectRowOnGrid(grid As SAPFEWSELib.GuiGridView, columnname As String, texttofind As String) 
  
          For i = 0 To grid.RowCount - 1
  
              If grid.GetCellValue(i, columnname) = texttofind Then
                  grid.DoubleClickCurrentCell
              End If
  
          Next i
  
  End Function
  </code></pre>
  
  <p>I have also tried the following code:</p>
  
  <pre><code>    Function SelectRowOnGrid(grid As SAPFEWSELib.GuiGridView, columnname As String, texttofind As String)
  
          For i = 0 To grid.RowCount - 1
  
            If InStr(1, grid.GetCellValue(i, columnname), texttofind, 1) &gt; 0 Then
  
              If selectedRows = "" Then
                selectedRows = CStr(i)
                  Else
                selectedRows = selectedRows + "," + CStr(i)
              End If
  
            End If
  
          Next i
  
      grid.selectedRows = selectedRows
  
  End Function
  </code></pre>
  
  <p>Any help is appreciated !</p>
  
  <p>cheers</p>