Stellar Blade Un'esclusiva PS5 che sta facendo discutere per l'eccessiva bellezza della protagonista. Vieni a parlarne su Award & Oscar!
 
Pagina precedente | 1 | Pagina successiva
Vota | Stampa | Notifica email    
Autore

codice colore per sumbycolor

Ultimo Aggiornamento: 22/04/2020 13:32
Post: 17
Registrato il: 30/10/2017
Città: ALBEROBELLO
Età: 41
Utente Junior
Excel per MAC 16.35
OFFLINE
17/04/2020 08:44

Ho all'interno di un file la necessità di usare il sumbycolor (ho anche già a disposizione la relativa macro).

Ma come fare a capire sulle celle colorate dove devo eseguire la somma, a che codice colore corrispondono?
Post: 312
Registrato il: 31/01/2010
Città: LIVORNO
Età: 61
Utente Senior
2016
OFFLINE
17/04/2020 09:21

Buongiorno forse se alleghi la macro qualcuno può aiutarti

A meno che qualcuno abbia la sfera di cristallo

Saluti






--------------
Marco
excel 2013
Post: 2.695
Registrato il: 06/04/2013
Utente Veteran
2010
OFFLINE
17/04/2020 10:08

ciao
per conoscere il colore di una cella, ti ci posizioni ed esegui questa riga di codice:

sub colore
msgbox activecell.interior.colorindex
end sub

(nota: non sempre i colori corrispondono in quanto per certe sfumature, excel raggruppa n colori; quanto suddetto si riferisce ai 56 principali colori, pertanto colore 15 per esempio potrebbe corrispondere a diverse sfumature. Qualora ciò avvenisse, è necessario ricorrere al codice RGB del colore)

Per quanto sopra, come detto da Marc63 bisogna conoscere che istruzione usa la tua macro per sommare celle colorate.

saluti



[Modificato da dodo47 17/04/2020 10:27]
Domenico
Win 10 - Excel 2016
Post: 17
Registrato il: 30/10/2017
Città: ALBEROBELLO
Età: 41
Utente Junior
Excel per MAC 16.35
OFFLINE
17/04/2020 11:30

la macro è questa

Function SumByColor(InRange As Range, WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Double
'
' This function return the SUM of the values of cells in
' InRange with a background color, or if OfText is True a
' font color, equal to WhatColorIndex.
'
Dim Rng As Range
Dim OK As Boolean

Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
OK = (Rng.Font.ColorIndex = WhatColorIndex)
Else
OK = (Rng.Interior.ColorIndex = WhatColorIndex)
End If
If OK And IsNumeric(Rng.Value) Then
SumByColor = SumByColor + Rng.Value
End If
Next Rng

End Function

ma la mia principale difficoltà è individuare un colore dalla tavolozza e capire che codice è. Quando mi scrivi di posizionarti sulla cella colorata e lanciare

sub colore
msgbox activecell.interior.colorindex
end sub

devo quindi creare una macro?
Post: 2.697
Registrato il: 06/04/2013
Utente Veteran
2010
OFFLINE
17/04/2020 11:40

...ho l'impressione di si; quella riga di codice ti restituisce il colore della cella attiva, pertanto potrai ottenere il tuo "WhatColorIndex "




[Modificato da dodo47 17/04/2020 11:41]
Domenico
Win 10 - Excel 2016
Post: 18
Registrato il: 30/10/2017
Città: ALBEROBELLO
Età: 41
Utente Junior
Excel per MAC 16.35
OFFLINE
17/04/2020 13:06

ok grazi

Potrei chiederti un'ultima cosa: io ad esempio scelgo un colore, il 43, con cui colorare la mia cella.

Devo usare poi un somma.se che mi permette di dire che se la mia cella ha il colore 43 spostati più in la per sommare altri valori, quindi dovrei realizzare una cosa di questo tipo:

+somma.se(A1:A20;CI SONO CELLE CON COLORE 43 in A1:A20?;K1:K20)

come fare a scrivere la condizione?
Post: 2.707
Registrato il: 06/04/2013
Utente Veteran
2010
OFFLINE
19/04/2020 11:17

Ciao
premesso che ti converrebbe farlo tramite codice, ci sarebbe una possibilità utilizzando INFO.CELLA (antidiluviana xl4 macro) utilizzando una colonna d'appoggio nella quale inserire 43 se la relativa cella in col. A abbia il colore 43.
(Potendo, puoi usare anche la colonna A.)

Ti allego esempio in cui ho utilizzato la col. C come appoggio.
In tale colonna c'è il riferimento ad un nome predefinito (=ColoreCella) che contiene la seguente istruzione:

=INFO.CELLA(63;INDIRETTO("rc[-2]";FALSO))

"giocando" con il riferimento RC puoi utilizzare qualsiasi altra colonna; avendo io usato la col. C, la funzione analizza il colore della cella posta due colonne a destra [-2].

Infine utilizzi il somma.se: =SOMMA.SE(C1:C20;43;K1:K20)

saluti
(NOTA: il file deve essere xlsm)






[Modificato da dodo47 19/04/2020 12:23]
Domenico
Win 10 - Excel 2016
Post: 20
Registrato il: 30/10/2017
Città: ALBEROBELLO
Età: 41
Utente Junior
Excel per MAC 16.35
OFFLINE
20/04/2020 07:58

scusami, e quel 63 nell'argomento della formula dell'info cella starebbe per...?
Post: 2.719
Registrato il: 06/04/2013
Utente Veteran
2010
OFFLINE
21/04/2020 16:28

pensa è così vecchia che neanche più MCS lo riporta.
Quasi quasi mi dispiace pubblicarli, sono una rarità e patrimonio di pochi "anziani" 😉:
(comunque fossi in te sarei cauto con il suo utilizzo)

1 Absolute reference of the upper-left cell in reference, as text in the current workspace reference style.
2 Row number of the top cell in reference.
3 Column number of the leftmost cell in reference.
4 Same as TYPE(reference).
5 Contents of reference.
6 Formula in reference, as text, in either A1 or R1C1 style depending on the workspace setting.
7 Number format of the cell, as text (for example, "m/d/yy" or "General").
8 Number indicating the cell's horizontal alignment:
1 = General​
2 = Left​
3 = Center​
4 = Right​
5 = Fill​
6 = Justify​
7 = Center across cells​
9 Number indicating the left-border style assigned to the cell:
0 = No border​
1 = Thin line​
2 = Medium line​
3 = Dashed line​
4 = Dotted line​
5 = Thick line​
6 = Double line​
7 = Hairline​
10 Number indicating the right-border style assigned to the cell.
See type_num 9 for descriptions of the numbers returned.​
11 Number indicating the top-border style assigned to the cell.
See type_num 9 for descriptions of the numbers returned.​
12 Number indicating the bottom-border style assigned to the cell.
See type_num 9 for descriptions of the numbers returned.​
13 Number from 0 to 18, indicating the pattern of the selected cell
as displayed in the Patterns tab of the Format Cells dialog box,​
which appears when you choose the Cells command from the Format menu.​
If no pattern is selected, returns 0.​
14 If the cell is locked, returns TRUE; otherwise, returns FALSE.
15 If the cell's formula is hidden, returns TRUE; otherwise, returns FALSE.
16 A two-item horizontal array containing the width of the active cell and a logical value
indicating whether the cell's width is set to change as the standard width changes (TRUE)​
or is a custom width (FALSE).​
17 Row height of cell, in points.
18 Name of font, as text.
19 Size of font, in points.

20 If all the characters in the cell, or only the first character, are bold, returns TRUE; otherwise, returns FALSE.
21 If all the characters in the cell, or only the first character, are italic, returns TRUE; otherwise, returns FALSE.
22 If all the characters in the cell, or only the first character, are underlined, returns TRUE; otherwise, returns FALSE.
23 If all the characters in the cell, or only the first character, are struck through, returns TRUE; otherwise, returns FALSE.
24 Font color of the first character in the cell, as a number in the range 1 to 56. If font color is automatic, returns 0.
25 If all the characters in the cell, or only the first character, are outlined, returns TRUE; otherwise, returns FALSE.
Outline font format is not supported by Microsoft Excel for Windows.​
26 If all the characters in the cell, or only the first character, are shadowed, returns TRUE; otherwise, returns FALSE.
Shadow font format is not supported by Microsoft Excel for Windows.​
27 Number indicating whether a manual page break occurs at the cell:
0 = No break​
1 = Row​
2 = Column​
3 = Both row and column​
28 Row level (outline).
29 Column level (outline).
30 If the row containing the active cell is a summary row, returns TRUE; otherwise, returns FALSE.
31 If the column containing the active cell is a summary column, returns TRUE; otherwise, returns FALSE.
32 Name of the workbook and sheet containing the cell If the window contains only a single sheet that has the same
name as the workbook without its extension, returns only the name of the book, in the form BOOK1.XLS.​
Otherwise, returns the name of the sheet in the form "[Book1]Sheet1".​
33 If the cell is formatted to wrap, returns TRUE; otherwise, returns FALSE.
34 Left-border color as a number in the range 1 to 56. If color is automatic, returns 0.
35 Right-border color as a number in the range 1 to 56. If color is automatic, returns 0.

36 Top-border color as a number in the range 1 to 56. If color is automatic, returns 0.
37 Bottom-border color as a number in the range 1 to 56. If color is automatic, returns 0.
38 Shade foreground color as a number in the range 1 to 56. If color is automatic, returns 0.
39 Shade background color as a number in the range 1 to 56. If color is automatic, returns 0.
40 Style of the cell, as text.
41 Returns the formula in the active cell without translating it (useful for international macro sheets).
42 The horizontal distance, measured in points, from the left edge of the active window to the left edge of the cell.
May be a negative number if the window is scrolled beyond the cell.​
43 The vertical distance, measured in points, from the top edge of the active window to the top edge of the cell.
May be a negative number if the window is scrolled beyond the cell.​
44 The horizontal distance, measured in points, from the left edge of the active window to the right edge of the cell.
May be a negative number if the window is scrolled beyond the cell.​
45 The vertical distance, measured in points, from the top edge of the active window to the bottom edge of the cell.
May be a negative number if the window is scrolled beyond the cell.​
46 If the cell contains a text note, returns TRUE; otherwise, returns FALSE.
47 If the cell contains a sound note, returns TRUE; otherwise, returns FALSE.
48 If the cells contains a formula, returns TRUE; if a constant, returns FALSE.
49 If the cell is part of an array, returns TRUE; otherwise, returns FALSE.
50 Number indicating the cell's vertical alignment:
1 = Top​
2 = Center​
3 = Bottom​
4 = Justified​
51 Number indicating the cell's vertical orientation:
0 = Horizontal​
1 = Vertical​
2 = Upward​
3 = Downward​
52 The cell prefix (or text alignment) character, or empty text ("") if the cell does not contain one.

53 Contents of the cell as it is currently displayed, as text, including any additional numbers or symbols resulting from the cell's formatting.
54 Returns the name of the PivotTable view containing the active cell.
55 Returns the position of a cell within the PivotTableView.
56 Returns the name of the field containing the active cell reference if inside a PivotTable view.
57 Returns TRUE if all the characters in the cell, or only the first character, are formatted with a superscript font; otherwise, returns FALSE.
58 Returns the font style as text of all the characters in the cell, or only the first character as displayed in the Font tab of the Format Cells dialog box: for example, "Bold Italic".
59 Returns the number for the underline style:
1 = none​
2 = single​
3 = double​
4 = single accounting​
5 = double accounting​

60 Returns TRUE if all the characters in the cell, or only the first characrter, are formatted with a subscript font; otherwise, it returns FALSE.
61 Returns the name of the PivotTable item for the active cell, as text.
62 Returns the name of the workbook and the current sheet in the form "[book1]sheet1".
63 Returns the fill (background) color of the cell.
64 Returns the pattern (foreground) color of the cell.
65 Returns TRUE if the Add Indent alignment option is 0n (Far East versions of Microsoft Excel only); otherwise, it returns FALSE.
66 Returns the book name of the workbook containing the cell in the form BOOK1.XLS.



[Modificato da dodo47 21/04/2020 16:31]
Domenico
Win 10 - Excel 2016
Post: 793
Registrato il: 24/06/2015
Città: CATANIA
Età: 80
Utente Senior
Excel2019
OFFLINE
21/04/2020 17:33

Ciao
Grazie @dodo47

Questa la metto nella "cassetta degli attrezzi" e la conservo gelosamente.

Qualcosa (ma non quello che gentilmente hai pubblicato) si può trovare a questo indirizzo https://support.office.com/it-it/article/cella-funzione-cella-51bd39a5-f338-4dbe-a33f-955d67c2b2cf

Ciao,
Mario
Post: 2.720
Registrato il: 06/04/2013
Utente Veteran
2010
OFFLINE
21/04/2020 18:08

ciao Mario
occhio che Cella è diverso da info.cella

Info.cella (in inglese get.cel) fa riferimento alle antidiluviane macro XLM (no XML !!) risalenti alla versione 4 di excel.....

Se ti vuoi divertire:

https://exceloffthegrid.com/using-excel-4-macro-functions/

https://www.jkp-ads.com/Articles/ExcelNames08.asp

cari saluti




[Modificato da dodo47 21/04/2020 18:08]
Domenico
Win 10 - Excel 2016
Post: 24
Registrato il: 30/10/2017
Città: ALBEROBELLO
Età: 41
Utente Junior
Excel per MAC 16.35
OFFLINE
22/04/2020 13:32

Spettacolo, grazie
Vota:
Amministra Discussione: | Chiudi | Sposta | Cancella | Modifica | Notifica email Pagina precedente | 1 | Pagina successiva
Nuova Discussione
 | 
Rispondi
Cerca nel forum
Tag discussione
Discussioni Simili   [vedi tutte]
Feed | Forum | Bacheca | Album | Utenti | Cerca | Login | Registrati | Amministra
Tutti gli orari sono GMT+01:00. Adesso sono le 22:02. Versione: Stampabile | Mobile | Regolamento | Privacy
FreeForumZone [v.6.1] - Copyright © 2000-2024 FFZ srl - www.freeforumzone.com