Changes to the community structure and the menu bar
Significant changes have happened to the structure of our community and our drop down menu bar. READ ABOUT IT HERE
Unified Functional Testing User Discussions
cancel

For loop for import excel and skip empty cells

SOLVED
Go to solution
Highlighted
Xsi Valued Contributor.
Valued Contributor.

For loop for import excel and skip empty cells

Hello everyone ,


I have written following function

Its reading an excelfile also loop through a certain sheet also some columns,

Public sub ExcelDataToArr()

TestData=Environment.value("TestPath")&"Testdata\DB.xlsx"

Datatable.Importsheet (TestData),"TestDataDB",1

intRowcount=DataTable.GetSheet(1).GetRowCount
For iLoop = 1 To intRowcount


  DataTable.GetSheet(1).SetCurrentRow iLoop 
  
  If  iLoop <> "" Then
        Username= (DataTable.value("UserName",1))
        msgbox (Username)
  End If

 
Next

End Sub

but how do I add that the for loop is skipping empty cells in this case (username)

 

 

see my atempt

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Sperk Acclaimed Contributor.
Acclaimed Contributor.
Solution

Re: For loop for import excel and skip empty cells

This line is checking wheter the current row = "" which it never will as you are looping thru the count of rows in your datatable.

If  iLoop <> "" Then

What you have to do is check the contents of the data table cell, something like:

   If  DataTable.value("UserName") = "" Then
         Username= (DataTable.value("UserName")
End If

Mark Smith.

1 REPLY
Sperk Acclaimed Contributor.
Acclaimed Contributor.
Solution

Re: For loop for import excel and skip empty cells

This line is checking wheter the current row = "" which it never will as you are looping thru the count of rows in your datatable.

If  iLoop <> "" Then

What you have to do is check the contents of the data table cell, something like:

   If  DataTable.value("UserName") = "" Then
         Username= (DataTable.value("UserName")
End If

Mark Smith.