I need to know how many rows are in an excel worksheet.
I use the Read Range activity to create a datatable “mtmRowCnt” and then use the For Each row and in the Body use Assign to get a count of those rows. Where “mtmRows” is the generic variable assigned
This works perfectly in a difference automation and in the current one I get the error:
Compiler error(s) encountered processing expression “mtmRowCnt.Rows.IndexOf(row)”.
Option Strict On disallows implicit conversions from ‘Object’ to 'System.Data.DataRow".
I don’t have a programming background, Corporate Finance guy here, and do not understand what this is trying to tell me and why the same activities with the same variable types in the same locations does not want to work here. Any work around or suggestions would be appreciated.
Buddy @BradGuiso
Welcome to uipath community buddy and thats a great question to start with actually…nothing to worry that you dont know programming…its just a language buddy, you can used to it sooner or later
Great
you can get the row count by doing this buddy
Use excel application scope to open the excel and pass the filepath as input
Use read range activity to get the data from excel and get the output variable as out_dt of type datatable
Use a assign activity with variable of type integer and assign like this
Out_row_count = out_dt.Rows.count
This gives the count buddy @BradGuiso
And the error occurred because indexof returns the index value of that row in the datatable of type integer buddy and you were trying to assign it to a datàrow type
That certainly fixed the error however; I’m using that count of rows in a set of Read Range activities eg.- “A1:D”+mtmRows
When I make the changes above the Read Ranges now all have errors in them.
Buddy i would like to suggest you on this. If you are using this count with range…rather to do that we can just mention as “” range buddy that would read all the rows and columns, we dont need to get the row count and assign it to the range explicitly rather when we mention simply without any range been mentioned, it will take all the rows and columns buddy…or unless you need that to be read only untill D COLUMN, but thats not always sure buddy sometimes the no of rows might change know…
Cheers
my source data is a monthly excel file from a vendor. I need to copy some of that data into a SAP upload form. So I need to grab very specific columns and only the rows where the data is populated.
Fine if you want to know the values of only certain rows you can do the same but with small insertion…once aftrr getting the count do like this buddy in the range of read range activity
“A1:D”+(out_row_count).ToString
Buddy instead of validating the excel before the iteration we can check the data whether it is valid or not before entering them to SAP buddy @BradGuiso
And we can do this with certain condition buddy like if condition , this is the procedure buddy
Use excel application scope with file name as input.
Use read range activity with output variable named out_dt
Use a for each row loop ito iterate through each row of the datatable
Use a if condition to validate the row column value buddy
Like this
row(“columnname”).ToString.Equals(“value”)
Or
row(“columnname”).ToString.Contains(“value”)
Like this buddy @BradGuiso
Hope this would help buddy or not…no problem…lets sort this out…easy buddy
Cheers
Thanks @Palaniyappan. I’ll take a look at this in the morning and let you know what I find. I will also see if I can use my snip app and get a screen shot to show you where I started and where I’m going. Take care.
This one in another automation is working just fine.
Both are being used to set up a range within a data table to be copied. The table is not perfectly structured. The vendor includes some blank rows at the top and the column headers start in row three and the data I need is from row 4 through row “x” and “x” changes every month.
It seems strange that this works in one automation and not in a different one.
Buddy i think its just datatype issue,
if mtmRowCnt is of datatable, then in for each loop, the type argument should be of type datarow
and inside the for each loop may i know what is the type mtmRows on left side of assign activity and what value you are trying to send it…kindly mention that buddy @BradGuiso
Thats all buddy its just a datatype issue we can easily sort this out
Cheers
mtmRowCnt is a data table
mtmRows is a GenericValue
my command on the right side is mtmRowCnt.Rows.IndexOf(row) this works in the other file.
the generic value works perfectly in the Read Range activities where I’m assigning various ranges within the file to their own variable so I can paste them into a separate workbook.
Really appreciate you hanging in there with me @Palaniyappan
No worries buddy kindly change the type of for each loop with datarow
that was the reason for first issue,
and then you can write the same for assign activity that would work as it is
Cheers buddy @BradGuiso
Try this and let know whether this works or not buddy