# Convert negative string to positive in Excel without using Loops

Hi,

In my working sheet, the column name is “Amount” and it holds number in positive as well as negative.

-I am trying to convert all the -ve numbers in that column to positive as I have to compare those data with another data.
-I am reading the full excel sheet and storing it in a DT, so how can I convert the value? Amount.xlsx (10.1 KB)

@indrajit.shah For Converting negative numbers to Positive, you can use Math.Abs(yourNumber)

@supermanPunch
Ya but how can i utilize it in DT and write the new data in a sheet .

@indrajit.shah Can you follow these Steps :

2. Use For Each Row Activity For that DT
Inside For Each use An Assign Activity and Assign row(“Amount”) = Math.Abs(Convert.ToDouble(row(“Amount”).ToString))
3. Use Write Range Activity and Write the DT back to the Same Excel File

For Clarification Purpose, I recommend to use a Different Excel File as Output

3 Likes

@supermanPunch
I am looking for suggestion other than using loop.
but its good solution.

1 Like

The Linq can be used to update the column .

1 Like

@Priyanka_Ramesh
Do you mind sharing?
as once the data is updated i have take the data to work further.

How to drag a formula in the entire column in excel
Can you try this. Even in Linq the For loop has to be used .

1 Like

Hello @indrajit.shah

You can easily do this using linq

Check this workflow for better understanding
-ve to ve.xaml (6.8 KB)

3 Likes

I think if you only want this to be applied to your excel file, just use the ABS function in that column.

2 Likes

@vickydas
cool, I didn’t tried linq in UiPath.
i have a question too.

-The output of the “Output Data Table” Activity is string and so i can’t able to write the output in new excel.

hello @indrajit.shah

Output Datatable activity is used to convert the datatable to String
Why are you using Output Datatable activity if you don’t want it in string

Delete the Output Datatable activity and use write range activity with the Datatable type variable as Input

1 Like

Thankyou.

How stupid of me Hello @indrajit.shah
this is happening because of your excel sheets as the cells are formatted in Date so you get the date with time when you write it using Write Range Activity

Replace the String.Join(Query) in the code with this

`String.Join("|",DT.Columns.Cast(Of DataColumn).Select(Function(col) If(CStr(col.columnname)="Amount",x,If(CStr(col.columnname)="Date",CDate(roww.Item("Date")).ToShortDateString,roww.Item(col.columnname))))).Split("|"c)`
{"ft_lang_label":"__label__en","ft_lang_prob":0.9489078,"math_prob":0.4921131,"size":340,"snap":"2020-45-2020-50","text_gpt3_token_len":81,"char_repetition_ratio":0.10714286,"word_repetition_ratio":0.0,"special_character_ratio":0.24705882,"punctuation_ratio":0.103896104,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95447916,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-03T05:41:52Z\",\"WARC-Record-ID\":\"<urn:uuid:c7a31c2d-e063-4a46-91e1-54a3169dd732>\",\"Content-Length\":\"53228\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e7acc23e-5db4-4544-a1a5-713d0e5160f4>\",\"WARC-Concurrent-To\":\"<urn:uuid:3445aa5b-0fec-4d7a-8c83-7dee01a684cd>\",\"WARC-IP-Address\":\"64.62.250.111\",\"WARC-Target-URI\":\"https://forum.uipath.com/t/convert-negative-string-to-positive-in-excel-without-using-loops/202249\",\"WARC-Payload-Digest\":\"sha1:ZS5IVOCGAHNSXNSBNZIKQAS7NVGEI6L5\",\"WARC-Block-Digest\":\"sha1:DVZW6647VYN2T3ASJCKRI3N4MMV4CJRP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141718314.68_warc_CC-MAIN-20201203031111-20201203061111-00222.warc.gz\"}"}