I have been struggling with trying to write this (my first lo function),
so please be understanding of my inexperience.
The function should change the background color to an rgb value based on 3 cells.
So something like bgcolor(r,g,b) where r, g and b are either values or better cell references.
e.g. if I enter ‘
=bgcolor(c5,d5,e5)’ into cell
f5 it should change the background color of cell
function BGCOLOR(red, green, blue) CellBackColor = RGB(red, green, blue) end function
I know this is not correct and I have tried multiple things, but rather than including
more wrong code here would really appreciate if someone could help me out.
working solution, although I have hard coded the ranges.
Many thanks to the two people below who helped me out.
Sub bgcolor_range Dim oSheet As Object oSheet = ThisComponent.CurrentController.ActiveSheet Dim oCell As Object Dim row As Integer, col As Integer for row = 5 To 158 for col = 28 To 28 oCell = oSheet.getCellByPosition( col, row ) rrr = oSheet.getCellByPosition( col-3, row ).Value ggg = oSheet.getCellByPosition( col-2, row ).Value bbb = oSheet.getCellByPosition( col-1, row ).Value If oCell.String <> "" Then oCell.CellBackColor = RGB(rrr,ggg,bbb) next col next row End Sub