Makro möglich? Addieren auf Knopfdruck

Das Tabellenkalkulationsprogramm

Moderator: Moderatoren

Charly
*****
Beiträge: 450
Registriert: Di, 20.01.2004 13:14
Wohnort: München

Re: Makro möglich? Addieren auf Knopfdruck

Beitrag von Charly »

Hallo!

Ich habe dir mal ein Beispiel programmiert, wie man so was machen kann.

1. Summieren

Code: Alles auswählen

Sub Summieren()

Dok = ThisComponent
Controller = Dok.getCurrentController
Blatt = Controller.ActiveSheet

WertP5 = Blatt.getCellRangeByName("P5").value
WertQ5 = Blatt.getCellRangeByName("Q5").value
WertX1 = Blatt.getCellRangeByName("X1").value
WertX2 = Blatt.getCellRangeByName("X2").value

WertP5 = WertP5 + WertX1
WertQ5 = WertQ5 + WertX2

If WertP5< 120 then
Blatt.getCellRangeByName("P5").value = WertP5
else
Blatt.getCellRangeByName("P5").value = 120
end if

If WertQ5< 120 then
Blatt.getCellRangeByName("Q5").value = WertQ5
else
Blatt.getCellRangeByName("Q5").value = 120
end if

End Sub
2. Abziehen

Code: Alles auswählen

Sub Abziehen()

Dok = ThisComponent
Controller = Dok.getCurrentController
Blatt = Controller.ActiveSheet

WertP5 = Blatt.getCellRangeByName("P5").value
WertQ5 = Blatt.getCellRangeByName("Q5").value
WertX1 = Blatt.getCellRangeByName("X1").value
WertX2 = Blatt.getCellRangeByName("X2").value

WertP5 = WertP5 - WertX1
WertQ5 = WertQ5 - WertX2

If WertP5>= 0 then
Blatt.getCellRangeByName("P5").value = WertP5
else
Blatt.getCellRangeByName("P5").value = 0
end if

If WertQ5>= 0 then
Blatt.getCellRangeByName("Q5").value = WertQ5
else
Blatt.getCellRangeByName("Q5").value = 0
end if

End Sub
Gruß
Charly
clag
********
Beiträge: 3570
Registriert: Di, 27.01.2009 15:30

Re: Makro möglich? Addieren auf Knopfdruck

Beitrag von clag »

Hallo Charly,

dein BasicCode hat auch noch mehr/andere Freunde :)
Den hab ich mir dann auch gleich mal kopiert :D
LG
clag

nutzt: WinXP SP3 / AOO 4.1.10 / Firefox
Antworten