Copy / Write range with dynamic rows

First of all, thanks to help I’ve been given in the past, it’s much appreciated.

I have a new one. I get a file every week that has a list of programs and data within the file that I will simply need to read the range and then write the range to my weekly final output file.

However, the input file does not always come with each of our selected programs. See the screenshot below for an example mockup. I need to read/write program 1 from input to output, then since program 2 isn’t in the input, skip over that and select Program 3.

How would you do this?

@jwetherin

  1. loop through your input data using for each row in excel
  2. inside that use loop up based on program on final report sheet
  3. now use the output row number of look up to write the data to the respective cells

cheers

Hey Anil

Use “loop up” or “look up”?

@jwetherin

Lookup…my bad…typo

Cheers

No problem, gonna take your advice and do a bit more study on it and see what I got. Thanks.

1 Like

Hey can you expand on the If/Then Id need to use in my For Each Excel row loop?

Should I do a for loop and ADD “the rows that don’t exist into my file” and THEN read and write the range OR am I doing if/then to determine each row as a range individually to be read and written

Hi @jwetherin

To solve this issue of copying and pasting ranges with dynamic rows in UiPath, follow these steps using only native activities to keep it simple.

  1. Read the Input File: Use the Excel Application Scope activity and, inside it, the Read Range activity to read the entire input file (or a specific sheet if applicable). Store the result in a DataTable, for example, dt_Input.
  2. Filter Specific Programs: To ensure that we are copying only the specified programs, use the Filter Data Table activity to create a filtered table with just the programs you need. Set the filter, for example, Program = "Program 1" OR Program = "Program 3".
  3. Write the Range to the Output File: Open the output file using another Excel Application Scope activity. Inside it, use the Write Range activity to write the filtered table (dt_Filtered) to the destination sheet.
  4. Loop for Other Programs (Optional): If you want to iterate through a list of programs automatically, you can use a For Each Row on a DataTable that contains the list of programs to check. Add an If condition inside the loop to verify if the program exists in dt_Input before copying it.

Ill check into this. I actually went in the direction of a table join wizard. And while you can left join and pick up ALL the programs and any from the right table that have it and place null for those that don’t, trouble is it comes in like this

P1 —x
P2—88
P4—xyz
Total
P3—

So I am looking around to order/sort on these results above. My left join activity gets me the exact data I need it just has it all mucked up and out of order. that should be something I can do.

I am gonna close this topic, but wanted to show how I did what I needed to do.

Basically I used activities read range, join data tables, sort data tables and filter data tables.

I read a range into a dt for just the standard programs that are always in the file
I read a full range into a dt on my full data, filtering to get the exact columns I wanted
I left joined dt1 with dt2 and moved that into dt3, which I then sorted on the program columns to get the right order. From there I can just write to my cells as needed.

Conceptually it’s pretty simple, but it’s the first time I had used joins in UiPath, but so far looks great.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.