i want to autosum entire column of excel & write the sum value at bottom of that column in UiPath
but column position changes everytime
Read the dt and gice only start range as A1 so it will read data from whole sheet
Then dt.AsEnumerable.Sum(function(x) if(isnumeric(cdbl(x("column").tostring), cdbl(x("column").tostring,0)))
will give sum
And dt.rowcount will give thhe count…add 2 to get the last row and use write cell
Cheers
- Use the Read Column activity to read the values in the column that you want to sum. This will return a list of strings, which you can store in a variable.
- Use a For Each loop to iterate through the list of strings, and use the Int32.Parse or Double.Parse method to convert each string to a numeric value.
- Inside the loop, use a variable to keep track of the running total, and add the value of each string to the running total as you iterate through the list.
- After the loop has completed, you can use the Write Cell activity to write the sum value to the cell at the bottom of the column. Make sure to specify the correct cell address, and set the value of the cell to the sum value stored in your running total variable.
- If the column position changes every time, you can use the Find Column activity to search for the column with a specific header or name, and then use the column index returned by this activity to specify the correct column in the Read Column and Write Cell activities.
I hope this helps! Let me know if you have any questions.
Thanks!!!
You can try with LINQ expression to Sum the column Values
(From d in DtBuild.AsEnumerable Where Not (isNothing(d("Column Name")) OrElse String.IsNullorEmpty(d("Column Name").toString.Trim)) Select v = CDbl(d("Column Name").toString.Trim)).Sum(Function (x) x)
In the Write cell activity pass this as a Range Need to update the column index A, B , C .....
"A"+(DtBuild.Rows.Count+2).ToString
Check out the XAML file
SumUsingLINQ.xaml (8.4 KB)
Regards
Gokul
thanks to all for your response
My problem is column position is dynamic ,otherwise currently i’m calculating the sum & writing at bottom using VBA code
You can use Look Range activity to find the column position.
If anyone know how to handle this the pls help me.
I’m stuck at this point.
ok i will try this & get back