Seite 1 von 1
[GELÖST] Formel plus Text
Verfasst: Mi 1. Feb 2023, 17:05
von Ich Bins
Hallo zusammen,
LO 7.4.4.4 (x64)
mit nachfolgendem Code
Code: Alles auswählen
Sub Formel_plus_Text
oSheet=ThisComponent.Sheets.getByName("Tabelle1")
oSheet.getCellByPosition(3,27).FormulaLocal="=OBERGRENZE(BRTEILJAHRE(D26;D27;4)*12;0,5)"
End Sub
kann ich in angefügter Calc-Datei in Zelle D28
8,5
eintragen. Wie kann man der Formel noch Monate hinzufügen damit
8,5 Monate
in Zelle D28 steht?
Viele Grüße
Ich Bins
Re: Formel plus Text
Verfasst: Mi 1. Feb 2023, 18:06
von karolus
Hallo
Code: Alles auswählen
…… "=OBERGRENZE(BRTEILJAHRE(D26;D27;4)*12;0,5) & "" Monate"""
Re: Formel plus Text
Verfasst: Mi 1. Feb 2023, 18:15
von F3K Total
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
Re: Formel plus Text
Verfasst: Do 2. Feb 2023, 00:12
von Ich Bins
Hallo Karolus,
& "" Monate"""
war die Lösung.
Vielen Dank
Re: Formel plus Text
Verfasst: Do 2. Feb 2023, 00:13
von Ich Bins
Hallo F3K Total,
Dein Vorschlag ist eine elegante Lösung, wenn man mit den Monaten rechnen möchte.
Vielen Dank
Re: [GELÖST] Formel plus Text
Verfasst: Do 2. Feb 2023, 16:07
von F3K Total
Moin Du bist es,
Ich Bins hat geschrieben: ↑Do 2. Feb 2023, 00:13
Dein Vorschlag ist eine elegante Lösung, wenn man mit den Monaten rechnen möchte.
Das sehe ich anders.
Wenn man ein Tabellen
kalkulationsprogramm zum Schreiben von Texten missbraucht, braucht man auch nicht auf eine vernüftige Formatierung der Zahlen zu achten
Gruß R
Re: [GELÖST] Formel plus Text
Verfasst: Do 2. Feb 2023, 16:57
von karolus
Hallo
@F3K Total: ich bin ganz deiner Meinung, aber was kann man retten wenn jemand eine Zeitdauer in auf halbe »Monate« aufgerundet, als
»Fliesskomma-Monate darstellen, und zudem das Bedürfniss hat diese Formel per Makro zu erstellen?!
