ristoi General User


Joined: 25 Aug 2009 Posts: 24 Location: Järvenpää
|
Posted: Sat Jul 17, 2010 12:14 am Post subject: Counter for Calc |
|
|
Here is NimettyLaskuri macro as a counter on the first sheet of a spreadsheet of Calc. With each call of macro with the same argument the value of a cell corresponding that argument is incremented.
If NimettyLaskuri macro is assigned to an event it seems to need intermediate routine like Sub Main here. Or you can just out comment the argument part with brackets and ensure you have that cumbersome default name (NimettyLaskuriP1) for some cell used as the target cell. It is probable that you don't already have a cell with the same name so this avoid some possible mixup.
If target cell has already value, counting is starting from there but possible formula there is destroyed.
Regards
Risto
| Code: |
Sub Main
NimettyLaskuri "B3" 'Nimeksi kelpaa myös soluosoite tekstinä
End Sub
Sub NimettyLaskuri (optional sSolunimi as String)
REM tämä rutiini käyttää nimettyä solua, johon listätään joka kusukerralla +1
REM Ensimmäisellä taulukkolehdellä pitää olla NimettyLaskuriP1 niminen solu
REM tai sitten argumentissa pitää olla solun nimi tai viite tekstinä
REM (RJ)
DIM oLaskuriSolu as Object, oLehti as Object
DIM LTemp as Long
DIM sNimi as String
sNimi = "NimettyLaskuriP1" 'Oletusnimi laskurille
IF NOT IsMissing(sSolunimi) AND VarType(sSolunimi)=8 then sNimi = sSolunimi
oLehti = thisComponent.Sheets.getByIndex(0)
oLaskuriSolu = oLehti.getCellRangeByName(sNimi)
LTemp=oLaskuriSolu.getValue()
oLaskuriSolu.setValue(LTemp+1)
End Sub
|
|
|