How to copy a range from range to an existing sheet in another excel

Hi!

I wanted to copy a range of date in Sheet X file A to Sheet X file B (file B is an empty template utilizing numbers in Sheet X). Could you please provide some ideas? Thank you!

1 Like

Hi Buddy @fifi

Welcome to uipath community buddy

Great…

  1. use excel application scope to open the first excel with sheet X , by passing the file path as input
  2. use a read range activity to read the data in the sheetx, by passing input with sheet name and range as “” or any range you want say “A1:B20”, and the output would be a datatable type variable name it out_dt
    This will read first 20 rows in two columns A and B
  3. Now use write range workbook activity with iput of file path of new excel and sheet name where to enter the data and the datatable out_dt

Thats all buddy you are done…

Kindly revert for any queries and clarifications
Cheers

1 Like

Hi @fifi

  1. Use Excel Application scope to read data from File A by providing File Path as input argument.
  2. Inside Excel Application Scope use Read Range activity to get data from Sheet X by providing Sheet name. Here you will get Datatable(DT_FileAData) as output.
  3. Use one more Excel Application scope to read data from File B by providing File Path as input argument.
  4. Inside Excel Application Scope use Write Range activity to write data into Sheet X by providing DT_FileAData which will write whole data into File B

Regards,
Vijay.

1 Like

Hi! Thank you Palaniyappan! It work! Do you happen to know if after the write range activity if it is possible to save file B into another name as this is a template file. I would also wanted to create a loop to have different File As copied into File B. Is it possible?

Hi! Thank you Vijay! It works! Do you happen to know if after the write range activity if it is possible to save file B into another name as this is a template file. I would also wanted to create a loop to have different File As copied into File B. Is it possible?

yes buddy @fifi you can save it with new file just by using move file activity where pass the file b as source file path and new file name as destination path
like this
image

and to pass different file you can get like
Directory.Getfiles(“yourfolderpath”,“*.xlsx”) with assign activity with variable out_filepath of collection type like array of string

then use a loop to iterate through each file with for each loop and pass that variable to first excel application scope buddy @fifi very simple buddy

Cheers

1 Like

@fifi

yes it is possible. Please use Move File activity which will take two arguments.
one is From Path which is the source file and another is Destination path.

In destination path you give different name with Same Extension.

To get all files and loop through them use Directory.Getfiles(“FolderPath”,“Extensiontype”) which will give you list of files. On this list you can use For each loop to iterate through all files.

Regards,
Vijay.

1 Like

If this works and got resolved kindly close this topic with right comment marked as solution that could help other looking for ideas under your topic,

Cheers buddy @fifi

Hi! It works thank you! I just have a quick question. I just realized that the Sheet X in file A would have different names when I am doing the loop (eg. 1111_aaaa, 1112_aaaa, 1113_aaaa) so when I tried to read range it did not work… I tried to do

  1. assign activity: name = those for digits numbers
  2. assign activity: inputname = name + “_aaa”
  3. read range: sheet name = inputname

Could you please kindly advise how could i fix this? Thank you!

1 Like

Buddy you can get the sheet names in an excel like this

  1. Use excel application scope and it has a output variable property and name it as out_workbook which is of type workbook
  2. Then inside th scope use a assign activity where bwe can get the sheet names in an excel as a array of string by doing this
    Out_sheet_array = out_workbook.Getsheets
  3. Now you can use a for each loop passing this variable as input and changing the type argument as string, and you can pass the sheetname as item…to any activity you want like read range or write range…
    Thats all buddy
    Cheers @fifi
1 Like

Did that work buddy @fifi

Worked out! Thank you!

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