Seite 1 von 1

Re: Makro möglich? Addieren auf Knopfdruck

Verfasst: Fr, 27.02.2009 20:09
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

Re: Makro möglich? Addieren auf Knopfdruck

Verfasst: Sa, 28.02.2009 06:53
von clag
Hallo Charly,

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