How to have Excel detect what to copy in hundreds of different sheets?

I have this workbook with hundreds of sheets.

Each sheet has some contract info at the top.

Then at B35 there is a list of invoices from that contract. By default, there are 20 rows available for the invoices list, so if there were ten invoices, there will be also ten blank rows and then a Totals row.

However, if there were 30 invoices for that contract, the person responsible will have added 10 extra rows, so all the 20 standard 10 extra rows will have info, and then there will be the Totals row.

What I want is to go through each one of these hundreds of sheets in the workbook, copy the info between B35 and the Totals Row (but avoid copying the blank rows when there are less than 20 invoices) and paste it ALL on a single sheet, in a Database friendly format.

You could use a read cell(store result in variable, say cellValue), starting from cell B35, and loop it until it finds totals row. And inside the loop should be a If condition “Not string.IsNullOrWhiteSpace(cellValue)”, which will read the cell value only if it is non-empty.

Hope this makes sense.

1 Like

It makes a little sense, as I am not very used to work with Excel on UiPath.

Ok, everything must be inside a single Excel App Scope, right?

do… ther eis a DO box, where I will have several activities in Linear Fashion.

First is a READ cell. From B35.

Then it should write in another Excel file. But maybe it is easier to write in another sheet of the same file.

So it reads from Sheet 545, B35, stores value in variable “VarInVoiceCol1”. It writes into Sheet TableInVoices, B1

Now it must loop. I suppose to make the loop I must go outside Excel App Scope activity and have a variable that increases one by one. So the variable (VarCount) started as 35. Now it increases 1 to 36.

Back to Excel App Scope.

It reads from sheet 545, B36. Except I am not sure how to increase it to 36. The cell field of the ReadCell Activity is written as “B35”. Should it be "B"VarCount ???

Btw… how to do this:
“loop it until it finds totals row”

doing an "if variable content = “TOTAL” then stop, else add +1 to variable?

how to do that IF with an IF activity?

Because you must insert an activity inside the IF or ELSE.

If it’s else, I can add an assign activity inside.

But if the variable IS equal to “Total”, and the flow must continue… how do I make it continue?

Hmmm… I am getting a “read cell faulted” when trying to read B35.

Maybe because it’s a merged cell? However, unmerge the cells would create as much work as just copyng everything, because there are hundreds of sheets.

Hi @Rogerio_Penna,

Try this:


What is the error you are getting, screenshot would be helpful. Are u trying to read using a read cell?

For the loop, one of the several ways you could do is:

  1. Let us assume, there are 20 records and word “totals” appears in cell A55(=35+20). Read the cell value using “Read Cell” activity, mention starting cell as B36 and store the value in variable, cellRef.
  2. Initialize a variable named say counter=1.
  3. Use a while loop with condition “Not cellRef.Equals(“totals”)”, increment the counter by 1. This way u get the number of records.
  4. Assign variable totalCount= counter, outside the while loop.
  5. Use read range activity and assign range as B36:“B”+totalCount, store it in datatable(say DT). Now u can paste this DT any place u like.

Hope this helps.



Thanks RMunro, but that seems to assume I know the range of that table.

As I mentioned… I have by standard 20 rows for invoices in each sheet.

If a contract has less than 20 invoices, I get blank rows, and your solution would work.

But a contract may have more than 20 invoices. And in that case, all rows are filled with data and more rows are inserted to add more invoices.

Fixed the Error above. Output of reading Excel cannot be a string, nor an integer, nothing. It must be a GenericValue variable. This is the kind of thing that UiPath should be more intelligent about, instead of requiring user to manually change to a variable type that isn´t even directly listed in the dropdown menu when creating a variable.

Exactly. GenericValue is just not good programming.

However, looking through the posts I looks to me that you are only interested in the TOTAL amount of a sheet. If that is right, you could modify the Excel-sheets to have a total (=SUM) of all invoice lines (however many) at the top of the sheet, say E1.
If you have the total value in E1 on all 600 sheets you only have to loop sheets(number).Cell(“E1”).Value. This is faster and less error prone.
You need, however, to incorporate the sum-cell in all 600 sheets first :wink:
I don’t know if this is helpful or even an option for you.


Then you can input as many rows as you want then have the blanks remove with the filter, like I mentioned. If you still don’t like that solution. Another workaround is injecting a macro that counts the rows, read the cell where the result is and then use read range to read the range and finally do what you want to do with that info. There are many ways to do this. Good luck!

Hi Klaus. No, I actually do not want the Total.

The only reason I want to know the location of Total is because I don´t want the information below the Total.(nor itself).

This is the info I want. From each one of hundreds of sheets

and this is the format I ultimately want at the final table

Ok, I misread the situation, @Rogerio_Penna, sorry.
Then I guess, @rmunro’s way is propably the best option.

Hi all.

The program is working fine when it copies cells with data and check for the TOTALS line.

But if there are blank spaces BETWEEN the invoice rows and the TOTAL line, I get this error

I have declared (I think) all variables

the error I am getting (which I posted above) is happening because of the while loop with condition “Not cellRef.Equals(“totals”)

If I use that condition, whenever there is an empty cell for that variable being tested, I get the SystemNullReferenceException error.

Your condition works in sheets where there are no blank rows between B35 and TOTAL row. If there is a blank row before TOTAL, I get that error.

I replaced your condition with Not string.IsNullOrWhiteSpace(VarNum)

This one ends the sequence whenever it finds a blank row.

I get no errors with this condition, HOWEVER, if there are no blank rows, it will keep copying text beyond the invoices areas.

I tried using my condition that works with blank rows and gets no errors WITH your condition (using both AND and ANDELSE) your condition., but as soon as I put your condition. the error returns in case of blank rows (even if I invert…

Not string.IsNullOrWhiteSpace(VarNum) And Not VarNum.Equals(“TOTAL”)
Not VarNum.Equals(“TOTAL”) And Not string.IsNullOrWhiteSpace(VarNum)

both give me the error when finding a blank cell and trying to find “TOTAL” in it.