Error using the Assign activity Solution

Hi all, first post here.

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.

1 Like

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
you can get the row count by doing this buddy

  1. Use excel application scope to open the excel and pass the filepath as input
  2. Use read range activity to get the data from excel and get the output variable as out_dt of type datatable
  3. 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

Thats all buddy you are done…
Cheers @BradGuiso

For getting the total number of rows
Datatable.rows.count then you will get the total number of rows.

I’ll give that a try. Thanks!


Did that work Buddy… @BradGuiso

Hi @Palaniyappan and @devKarthikeyanR

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…

I need specific ranges copied in a certain order and written to a separate workbook.

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

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

  1. Use excel application scope with file name as input.
  2. Use read range activity with output variable named out_dt
  3. Use a for each row loop ito iterate through each row of the datatable
  4. Use a if condition to validate the row column value buddy
    Like this

Like this buddy @BradGuiso
Hope this would help buddy or not…no problem…lets sort this out…easy buddy

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.

1 Like

Sure buddy… Anytime @BradGuiso

Hi @Palaniyappan and @devKarthikeyanR

Here’s what I’m currently doing where it’s throwing an error

1 Like

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.

1 Like

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

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

1 Like

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

I think I did what you suggested. Still have error messages.

the right side of the assign is now mtmRowCnt.Rows.IndexOf(datarow)
mtmRows remains a genericvariable

did I do it right?


1 Like

Buddy mention like this buddy @BradGuiso