Seite 1 von 1

farbig markierte Felder zählen

Verfasst: Mi 20. Feb 2013, 13:46
von dropkicktobi
Hi zusammen,

ich möchte gern zählen lassen, wieviel mit "x" markierte Zellen einer Farbe in einer Zeile sind. Es fällt mir schwer das Problem zu formulieren, deßhalb schaut bitte mal in die angehängte Datei.

Grüße
Tobias 8-)

Re: farbig markierte Felder zählen

Verfasst: Mi 20. Feb 2013, 22:30
von F3K Total
Hi,
das geht per Makro etwa z.B. so

Code: Alles auswählen

Sub S_Count_colors
dim acolors (2,4) as variant
    acolors(0,0) = "Grün"
    acolors(0,1) = "Blau"
    acolors(0,2) = "Gelb"
    acolors(0,3) = "Rot"
    acolors(0,4) = "Weiss"
    acolors(1,0) = 44544
    acolors(1,1) = 39423
    acolors(1,2) = 15138560	
    acolors(1,3) = 16711680
    acolors(1,4) = -1   
    osheet = thiscomponent.sheets.getbyname("Test")
    orange = osheet.getcellrangebyname("B2:F7")
    oaddress = orange.rangeaddress
    nstartcolumn = oaddress.startcolumn
    nendcolumn = oaddress.endcolumn
    nstartrow = oaddress.startrow
    nendrow = oaddress.endrow
    for i = nstartrow to nendrow
        for j = nstartcolumn to nendcolumn
        ocell = osheet.getcellbyposition(j,i)
            for k = 0 to 4
                if ocell.cellbackcolor =  acolors(1,k) and ocell.formula = "x" then 
                acolors(2,k) = acolors(2,k)+1
                endif
            next k
        next j
        for l = 0 to 4
            otargetcell = osheet.getcellbyposition(8+l,i)
            otargetcell.value = acolors(2,l)
            acolors(2,l) = 0
        next l
    next i
End Sub
Siehe Beispiel