How to set cell color in excel with input as a list of cell references

Hello everyone,

I have a list of random excel cell references like {“A4”,“C6”,“D5”,“E7”,“X3”,“Y5”,“Z9”}
I want to set background color as yellow of above mentioned cells.

At the moment, I am looping through the list and set each cell color one by one using “Set Range Color” activity under the Excel Application Scope. The problem is, I have very large list of cells which takes long time, just to set colors on them.

Anyone have idea how to set background color on random list of cell references effective way like using VBA or any other codes?

Thanks in advance.

Hi @MGP
this post from stack overflow seems to be matching with your query

Regards,
Nived N
Happy Automation

Hi,

Follow below step to add color in sheet cell.

  1. Open Excel in the Excel Application Scope activity. Place the Set Range Color activity inside the Excel Application Scope activity.

image

  1. Set the properties of the Range Color activity.

@MGP

I guess the method you are following here is only option as it is random cells. If it is adjacent cells then you can apply colour in one sort.

Thanks @NIVED_NAMBIAR,

I tried to tweak this code, but unfortunately it is not working.

Thanks @ghazanfar for the reply but I am already using this method which is really slow, as we can not pass random cell range all at once in this activity. That’s why I am looking for more efficient solution.

Thanks @lakshman for the comment.
That’s why would like to ask into community if anyone has different idea! :slight_smile:

Hi,

You can invoke vb.net code for that. I hope it will take less time. Are you using loop for for coloring that specific cell? Cuz looping cause slowness.

Dim workbook As Workbook = New Workbook
workbook.LoadFromFile(“…\Backgroundcolor.xls”, ExcelVersion.Version97to2003)
Dim worksheet As Worksheet = workbook.Worksheets(0)
set the backgroundcolor of Range[“A1:D1”]
worksheet.Range(“A1:D1”).Style.Color = Color.LightSeaGreen

import library
Imports Spire.Xls`