Moin,
versuche es so:
Code: Alles auswählen
Sub Formel_plus_Text
Dim aLocale As New com.sun.star.lang.Locale
oFormats = ThisComponent.NumberFormats
oFormatString = "0,0 ""Monate"""
nFormatDatumID = oFormats.queryKey( oFormatString, aLocale, True )'Gibt den Formatkey zurück, wenn nicht gefunden: -1
If nFormatDatumID < 0 Then
nFormatDatumID = oFormats.addNew( oFormatString, aLocale )'Format hinzufuegen wenn nicht vorhanden
endif
oSheet=ThisComponent.Sheets.getByName("Tabelle1")
oCell = oSheet.getCellByPosition(3,27)
oCell.FormulaLocal="=OBERGRENZE(BRTEILJAHRE(D26;D27;4)*12;0,5)"
oCell.Numberformat = nFormatDatumID
oCell2 = oSheet.getCellByPosition(5,27)
oCell2.FormulaLocal= "=2*D28"
oCell2.Numberformat = nFormatDatumID
End Sub
Da wird kein String "Monate" angehängt, sondern das richtige Zahlenformat eingetragen, so dass du mit der Zelle auch rechnen kannst. Lass das Makro mal so laufen und schau dir danach Zelle F28 an. Da müssten dann doppelt so viele Monate wie in D28 stehen.
Gruß R