Connect HomeMarketplaceComponentsCalculate Sum of Colored Cells in Excel Sheet

Calculate Sum of Colored Cells in Excel Sheet

Snippet

Snippet

Updated: September 30th, 2020

Published: October 25th, 2019

Downloads: 20

Language compatibility: Visual Basic

Community Support

Calculate Sum of Colored Cells in Excel Sheet

Snippet

Summary: 

Calculate the Sum of Excel colored cells in any given range

Using VBA, this snippet helps you calculate sums between any colored Excel cells within a given range.
Note: This function does not cover the case when only the text is marked with other font colors.
Please check the below screenshot illustrating the case when the sum of Green highlighted cells from the given data range needs to be calculated.
How it works:
Fill in manually the color in the data range. You can also use conditional formatting.
Select a reference cell. This needs to be highlighted in the color you are interested in. E.g. green
Access UiPath Studio.
In Invoke VBA activity type in the necessary Arguments values.
Arguments Details:
  • Colorcell - this is the reference cell. Manually enter the color, the same as the one in the data range. Then enter the cell number in the Argument Value. E.g. G6
  • Range – type in the data range. E.g. D6:E21
  • SheetName – enter the name of the sheet where the data, Colorcell and SumResult, are displayed. E.g. Sheet2
  • SumResult – add here the location where the Sum obtained after Bot execution will be displayed. E.g. H6
  • Workbookpath – enter the full Excel file path.
  • OutputValue- use this optional argument to store the end result.
  • wb – use this optional argument to close the workbook after the execution is completed.
Once all the required values have been updated in the necessary Arguments fields you are ready to run the Bot.
Please make sure that before you run this snippet, you enable the Excel Trust Access to the VBA project object model. Otherwise, an error will be displayed.
  • Enable it by following the path: from your Excel access File > Options > Trust Center > Trust Center Settings > Macro Settings > Select the Trust Access to the VBA project object model check box.
This snippet can be used to run for more than one color. Simply copy and add in the invoke VBA the number of times and the number of colors. Change the color cell info and the Sumresult Value.

Details

Benefits

Used to sum color cells based on color given in Reference cell
It works even if we color the cells in the given range using conditional formatting
Does not require macro enabled Excel file (.xlsm extension file)

Compatibility

UiPath Community version - 2019.10

Dependencies

Excel, UiPath 2019.10

Licensing

By clicking download you agree to the following license.