Addition of two columns

Here i have 2 columns columnA and columnB having integer values and i wanted the addition result of columnA and columnB in 3rd column i.e. columnC. But i want this in 2 different way.

Q1. Keeps the excel open and writes the result in real time, row by row so you can see the changes.
Q2. Keeps the excel closed,set the column values in the memory DataTable and adds all the tables to the excel file at once in the end.

Experts pls help

Hi @Tabbu

Please try this,

  1. For q1 we can use VBA to put an formula and filldown it.
Sub filldow()
  Range("C2").value = sum(A1:b1)
  Range("C2:C" & cells(rows.count,1).end(xlup).row).filldown
End sub

Refer this for how to use vba in UiPath

  1. For q2 follow the below steps,

  2. Read the excel sheet data in the datatable variable name dt.

  3. Add a activity called build datatable(output dt2) and give 3 column name (all are int).

  4. Use write range and give the query as below in datatable property,

(From dtRow in dt.asenumerable
Let a = cint(dtRow(0).tostring)
Let b = cint(dtRow(1).tostring)
Let c = a+ b
Select dt2.rows.add({a,b,c})).copytodatatable

Thanks

Hi @Tabbu,

For Q1:

Try to use excel components from app integration under the excel activities package.

.

This workflow opens the excel file and writes the data.

For Q2:


image
Use workbook activities without excel application scope

Can you pls show me properly what u have written in assign activity.And where is the addition of two columns u did? And also i wanted to write the result in columnC.

Thanks for your effort!!

CurrentRow.ByField[“c”]=CurrentRow.ByField[“A”]+CurrentRow.ByField[“B”].

In the assigned statement itself, I did the addition, and it is automatically written on the c column

image

Sorry i mean for Q2. What is written in assign activity

CurrentRow[2]=Convert.ToInt32(CurrentRow[0])+Convert.ToInt32(CurrentRow[1])



Getting this error

Which language you are using to code vb or c#?

Code vb

Ok. I have used C# here. The below code is for vb
CurrentRow(2)=Convert.ToInt32(CurrentRow(0))+Convert.ToInt32(CurrentRow(0)).Try this code and let me know whether it works or not.

Getting error in assign activity
“exception has been thrown by the target of an invocation”

Screenshot please