Running a macro and getting an error

Agree, this is better than “the macro quickly doesn’t work” :slight_smile:

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

Great! :smiley: it works very fast and correctly.
Trying to understand your macro… but it’s to much advanced for me :blush:
Many thanks for your help!!

There’s nothing special about it - it just creates conditional formatting like this
image

As you can see it’s not that difficult

Yes, I understood that. That’s why I suggested slow options, but easy to read