How to retrieve a cell value using LibreOffice Basic

In CALC I want to retrieve a cell value, change the cell’s style property (NB: without relying on predefined styles!) depending on that value and write the whole back again (or to a different location).
What is the LO macro code text for achieving that?

Generally it is suggested to study the api and its usage from LibO BASIC in advance of writing user code. There is this BASIC guide as available from an independent server (probably no longer provided by the document foundation). It should be virtually the same content as the guide made for OpenOffice.org BASIC. How to use the api may be much better explained by the famous texts by Andrew Pitonyak available here.

If you need help with a specific task like the one you talked of, you should always explain for what reason you think to need user code for what you eventually want toi achieve. There are to many requests by users who didn’t thoroughly consider the appropriate means (probably mislead by Excel and VBA).

Frankly spoken your request seems to be of the kind. What good for? There is conditional formatting and there are named cell styles applicable (under conditions if needed) with the help of the STYLE() function. For a thorouhghly designed sheet there should be no need of user code doing things of the kind. By theway: There are lots of cell properties.

Editing:
There are many details you need to learn about the LibreOffice api (here in specific concerning Calc). I already hinted some sources, and will not write a new tutorial. You may study this attached example. Please note that I do not obey some common ways of naming.
Concerning the attachment: The code contained a naming error. For reasons I do not understand it worked nonetheless for me. As I don’t know how this might be on a different system I replace the old attachment with one having the mentioned error eliminated.

Thnx for your comment, Lupp. What I want to achieve is this: given any output of the function COLOR in a cell, have the cell (or another) show the corresponding background color. Has something to do with generation of (random) palettes. You need too many a predefined conditional formatting styles to realize that using STYLE, agree? And a lot of dumb handwork too. That’s why one automates tasks.

quoting @m.p.de.graaff:"…given any output of … COLOR in a cell…"
What cell? IoW: In what way do you intend to pass the cells you want to work on to the Sub. Any one of the operations you want to perform will have a source cell and a target cell regarding the property .CellBackColor. If you know the ways to access all the pairs of cells you want to work on as pairs of objects it is simple:
targetCell.CellBackColor=sourceCell.CellBackColor will do the trick.

In what way do you want to give (identify) the specific cell to work on?

Hello @m.p.de.graaff,

Please see if the following macro does what you want:

Sub cellRange_Colorize( strRange as String )
REM Set the background color of each cell within <strRange> to the color value specified within that cell.
REM Example call: cellRange_Colorize( "A1:A99" )
	Dim oSheet As Object  : oSheet = ThisComponent.CurrentController.ActiveSheet
	Dim oRange As Object  : oRange = oSheet.getCellRangebyName( strRange )
	Dim oCell As Object
	Dim i As Integer, j As Integer
	For i = 0 To oRange.Rows.getCount() - 1				REM Traverse all cells in the specified range:
		For j = 0 To oRange.Columns.getCount() - 1
			oCell = oRange.getCellByPosition( j, i )
			If oCell.String <> "" Then oCell.CellBackColor = oCell.Value
		Next j
	Next i
End Sub

HTH, lib

Well, that looks pretty much like what I am looking for, Librebel. This helps. Thnx-a-lot!!
I started out from macro recording and, hence, was confronted with UNO-code BASIC. This looks more like the good old BASIC I remember from earlier days :wink: