cancel
Showing results for 
Search instead for 
Did you mean: 

How to set Color to a cell in Excel

NagaYaparla
Level 4
Hi All, I am trying to fill color to a specific cell in excel, any one has any idea please comment this post.   Thanks in advance..
7 REPLIES 7

franlem2
Level 4
Hi, Depending on your version perhaps can you set rules into Excel to fill this cell here : https://support.office.com/en-gb/article/apply-create-or-remove-a-cell-style-472213bf-66bd-40c8-815c-594f0f90cd22 If this option does not apply to you, I would recommend to create a VBA Macro to handle it.

franlem2
Level 4
... then you run the macro from BP with the Excel VBO.

AndreyKudinov
Level 10
Or you can add action to excel VBO to do it, should be easy, code was somewhere on the forum if I remember correctly.

nadiim
Level 3
Code Dim xl, wb, ws, r, i, f as object Try     xl = GetInstance(Handle)     if Workbook_Name = "" then         wb = xl.activeworkbook     else         wb = xl.workbooks(Workbook_Name)         wb.activate     end if     ws = wb.activesheet     if Ref.Trim = "" then         r = ws.usedrange     else         r = ws.range(Ref)     end if     i = r.Interior     i.ColorIndex = Background_Colour     f = r.Font     f.ColorIndex = Foreground_Colour Catch e As Exception     Success = False     Message = e.Message Finally     xl = Nothing     wb = Nothing     ws = Nothing     i = Nothing     r = Nothing     f = Nothing End Try  

Juan_ManuelFon1
Level 2
You can use the set cell color Action In the MS Excel VBO.

------------------------------
Juan Manuel Fonseca
Rpa developer
Freelance
America/Mexico_City
------------------------------

Hi!
Where can I find the MS Excel VBO-set cell color Action for downloading?
Thanx

------------------------------
SOFÍA ROLDÁN GARCÍA
------------------------------

Create additional action in excel vbo

code:
For Each row As DataRow In rowscoll.Rows
GetWorkbook(handle,Nothing).ActiveSheet.Cells(row.Item("Value"),colref).Interior.Color = RGB(Red_Value, Green_Value, Blue_Value)
next row

Inputs to the action:
25988.png
Action:
25989.png

ColRef is number of the column
rowscol is collection of row numbers to color

------------------------------
Karol Pietrzyk
------------------------------