# Excel Write Range not copying format

**URL:** <https://forum.uipath.com/t/excel-write-range-not-copying-format/183413>\
**Category:** Help\
**Tags:** datatable, excel, error, activities\
**Created:** [January 9, 2020, 1:23am UTC](https://forum.uipath.com/t/excel-write-range-not-copying-format/183413 "2020-01-09T01:23:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlor](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/carlor/32/176794_2.png) [@carlor](https://forum.uipath.com/u/carlor)\
**Post date:** [January 9, 2020, 1:23am UTC](https://forum.uipath.com/t/excel-write-range-not-copying-format/183413/1 "2020-01-09T01:23:05Z")

</div>

Hi everyone,

We’ve run into a bit of a situation using Write Range; it’s not copying the data format from the source. Here’s the scenario:

- load a DataTable from an Access database with multiple columns
- open an existing Excel file
- clear a range of cells
- paste the DataTable to the range just cleared

The problem is we sometimes have columns with data like “005” but when the data is pasted, the cells reformat to “5”. The column’s format in the Excel file is set to General. However, if we do it manually (select all data from Access, CTR-C, and paste in Excel) the proper format is retained. The default paste in Excel maintains the source cells’ format; there is another paste option that allows you to maintain the destination cells’ format

To make matters worse, the client needs the data to be in the “005” format, there are many Excel files with multiple tabs in each AND we don’t know which columns need to retain that format. We are automating their manual process.

I understand there are ways to force the format such as prepending the cells with an apostrophe or formatting the cells, but as I mentioned, we won’t know in advance which columns need to retain the format.

Any thoughts?

Thanks,

Carlo.

---

<div class="post-metadata">

**Author:** ![jcvsalinas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jcvsalinas/32/123029_2.png) [@jcvsalinas](https://forum.uipath.com/u/jcvsalinas)\
**Post date:** [January 9, 2020, 2:03am UTC](https://forum.uipath.com/t/excel-write-range-not-copying-format/183413/2 "2020-01-09T02:03:59Z")

</div>

@carlor

After write range you can use an invoke code activity to set the format using [vb.net](http://vb.net) [how to set excel cell format in vb.net - Stack Overflow](https://stackoverflow.com/questions/30297272/how-to-set-excel-cell-format-in-vb-net)

---

<div class="post-metadata">

**Author:** ![jcvsalinas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jcvsalinas/32/123029_2.png) [@jcvsalinas](https://forum.uipath.com/u/jcvsalinas)\
**Post date:** [January 9, 2020, 2:07am UTC](https://forum.uipath.com/t/excel-write-range-not-copying-format/183413/3 "2020-01-09T02:07:08Z")

</div>

> [@Excel - Format column to text before writing](https://forum.uipath.com/t/excel-format-column-to-text-before-writing/134447/2):
>
> @mohammedamaan, I don’t think we have activities to do that, but if you have few rows of data and (I hope you are trying to write a number into fields and they are converting to some other formats ), you can directly paste the values by appending “'” , I mean (') a single quote before the data so that it will write as it is. If you have huge data, or anyway you want to change the format and you want to write the values, here is a piece of code which will help you in changing the formats Di…

---

<div class="post-metadata">

**Author:** ![carlor](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/carlor/32/176794_2.png) [@carlor](https://forum.uipath.com/u/carlor)\
**Post date:** [January 9, 2020, 5:00am UTC](https://forum.uipath.com/t/excel-write-range-not-copying-format/183413/4 "2020-01-09T05:00:24Z")

</div>

The problem with that solution is having to know in advance which columns and which cells within those columns that I would have to set the format. Plus, that would change the layout of the original file because the original formatting is “General” and this would change it to “text”.

---

<div class="post-metadata">

**Author:** ![carlor](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/carlor/32/176794_2.png) [@carlor](https://forum.uipath.com/u/carlor)\
**Post date:** [January 9, 2020, 5:03am UTC](https://forum.uipath.com/t/excel-write-range-not-copying-format/183413/5 "2020-01-09T05:03:28Z")

</div>

Again, I would have to know in advance which cells in which columns in which tabs in which excel files need to have the data formatted.

I was hoping there was a solution I missed.

Thanks,

Carlo.
