Agree, this is better than “the macro quickly doesn’t work”
Okay, try this - it should work pretty quickly.
Sub setCFColor()
Dim oSheet As Variant, oCursor As Variant, oRange As Variant
Dim oConFormat As Variant, sColACRangeAddress As String, lastRow As Long
Dim oCondition(3) As New com.sun.star.beans.PropertyValue
oCondition(0).Name = "Operator"
oCondition(0).Value = com.sun.star.sheet.ConditionOperator.FORMULA
oCondition(1).Name = "Formula1"
oCondition(2).Name = "Formula2"
oCondition(2).Value = 0
oCondition(3).Name = "StyleName"
oSheet = ThisComponent.getSheets().getByName("BD-direta")
oCursor = oSheet.createCursor()
oCursor.gotoEndOfUsedArea(True)
lastRow = oCursor.getRangeAddress().EndRow
oRange = oSheet.getCellRangeByPosition(3, 1, 4, lastRow)
sColACRangeAddress = oSheet.getCellRangeByPosition(0, 1, 2, lastRow).AbsoluteName
oConFormat = oRange.ConditionalFormat
oConFormat.clear()
oCondition(1).Value = "LEN(VLOOKUP(A1;" & sColACRangeAddress & ";3;0))>1"
oCondition(3).Value = "Good"
oConFormat.addNew(oCondition)
oCondition(1).Value = "LEN(VLOOKUP(A1;" & sColACRangeAddress & ";3;0))<2"
oCondition(3).Value = "Error"
oConFormat.addNew(oCondition)
oRange.ConditionalFormat = oConFormat
ThisComponent.calculate()
End Sub