0

While looping through an SAP table, I get the run time error 614 "The enumerator of the collection cannot find en element with the specified index", when I reach a blank row.

Using the Rowcount method does not get me the the correct amount of non-blank rows. Any ideas on how I can get rid of the error or get another way to loop through only non-blank rows?

 Sub Process1
        Dim SAP_table1 AS Object
        Dim RowAmount As Integer
    

// Specifying SAP table

   RowAmount = SAP_table1.RowCount // Does not return the correct amount of non-blank rows

    Do While SAP_table1.Columns.Item(1).ElementAt(J).DisplayedText <> ""   // I get the run time error 614 here when I reach a blank cell
    
       // Do something
        J = J + 1
    
    Loop
End Sub
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Markuss
  • 5
  • 3
  • I think you have to use `RowCount - 1` – Storax Jul 25 '22 at 19:49
  • The RowCount is giving me 33 while the amount of non-blank rows is 5. So I don't think this will help. – Markuss Jul 26 '22 at 05:37
  • Maybe I was not concise enough. If you loop through a table with number of rows `rowcount` you have to stop at `rowcount - 1`. Otherwise you will run into an error. Your loop condition does not do that. Your code will possibly also not work in case the number `rowcount` is bigger than number of `VisibleRowCount`. It seems that this is right now not the case for you but it could be. [Reading material](https://help.sap.com/docs/sap_gui_for_windows/b47d018c3b9b45e897faf66a6c0885a8/ce1d9e64355d49568e5def5271aea2db.html?version=760.03&locale=en-US) – Storax Jul 26 '22 at 06:10
  • Addtional [reading material](https://tricktresor.de/wp-content/downloads/StSchnell_ReadTableWithSAPGUIScripting.pdf) , unfortunately only in German but maybe it helps – Storax Jul 26 '22 at 06:20
  • I changed the loop to " For J = 0 To SAP_table1.RowCount -1 " and it still gives me an error when a blank row is reached. The same happens if I use " For J = 0 To SAP_table1.VisibleRowCount -1 " – Markuss Jul 26 '22 at 06:25
  • MO you now need to edit your post in order to give more details. Which transaction ? Or ist is SE16 with which table? It's also a good idea to add your try with the `for` loop – Storax Jul 26 '22 at 07:35
  • 1
    And you need to indicate that we're talking about a `GuiTableControl` object, to not confuse with `GuidGridView` object. Note that you must scroll to reach non-visible rows, and you must reinstantiate your variables. See my answer [how it works](https://stackoverflow.com/questions/68685911/reading-text-in-va02-table-control). – Sandra Rossi Jul 26 '22 at 08:07

0 Answers0