Question sur SpecialCells VBA

L

ljoue

Guest
Bonjour,

En VBA SpecialCells défini un type de Cellule :

ex : SpecialCells(xlCellTypeBlanks) ---> Cellule Vide

Comment se traduit en VBA cette formule pour une cellule contenant du texte (ex : "date") ou qui est en couleur (ex : gris) ?

SpecialCells(xlCellType........????)

Merci d'avance

Cordialement,
Laurent
 
@

@+Thierry

Guest
Bonsoir Laurent,

Voici ce que donne l'aide VBA en version amércaine :

SpecialCells Method
Returns a Range object that represents all the cells that match the specified type and value. Range object.

expression.SpecialCells(Type, Value)

expression   Required. An expression that returns one of the objects in the Applies To list.

Type  Required XlCellType. The cells to include.

XlCellType can be one of these XlCellType constants.
xlCellTypeAllFormatConditions.  Cells of any format
xlCellTypeAllValidation. Cells having validation criteria
xlCellTypeBlanks. Empty cells
xlCellTypeComments. Cells containing notes
xlCellTypeConstants. Cells containing constants
xlCellTypeFormulas. Cells containing formulas
xlCellTypeLastCell. The last cell in the used range
xlCellTypeSameFormatConditions.  Cells having the same format
xlCellTypeSameValidation.  Cells having the same validation criteria
xlCellTypeVisible. All visible cells

Value  Optional Variant. If Type is either xlCellTypeConstants or xlCellTypeFormulas, this argument is used to determine which types of cells to include in the result. These values can be added together to return more than one type. The default is to select all constants or formulas, no matter what the type. Can be one of the following XlSpecialCellsValue constants:

XlSpecialCellsValue can be one of these XlSpecialCellsValue constants.
xlErrors
xlLogical
xlNumbers
xlTextValues

Pour d'autres recherche de types de cellules, il faut passer par d'autres méthodes ou fonctions (Eg.: IsDate pour Date, IsNuméric etc...)

Bonne Soirée
@+Thierry
 
@

@+Thierry

Guest
Ah oui j'avais fait ça pour le fun...

Sub CelluleFullStatistique()
Dim Plage As Range
Dim Total As Byte, NonVide As Byte, ValText As Byte, _
ValNume As Byte, ValForm As Byte, _
ValErre As Byte, ValVide As Byte, _
ValCond As Byte, ValComm As Byte, _
ValVali As Byte, valVisi As Byte

Set Plage = Sheets("Feuil1").Range("A5:A10")

Total = Plage.Count

On Error Resume Next
        NonVide = Plage.SpecialCells(xlCellTypeConstants, 23).Count
        ValVide = Plage.SpecialCells(xlCellTypeBlanks).Count
        ValText = Plage.SpecialCells(xlCellTypeConstants, xlTextValues).Count
        ValNume = Plage.SpecialCells(xlCellTypeConstants, xlNumbers).Count
        ValForm = Plage.SpecialCells(xlCellTypeFormulas).Count
        ValErre = Plage.SpecialCells(xlCellTypeFormulas, xlErrors).Count
        ValCond = Plage.SpecialCells(xlCellTypeAllFormatConditions).Count
        ValComm = Plage.SpecialCells(xlCellTypeComments).Count
        ValVali = Plage.SpecialCells(xlCellTypeAllValidation).Count
        valVisi = Plage.SpecialCells(xlCellTypeVisible).Count
       

MsgBox "La Zone contient " & Total & " cellules répartient comme suit : " & vbCrLf _
& vbTab & "Cellule Non Vide" & vbTab & vbTab & ": " & NonVide & vbCrLf _
& vbTab & "Cellule Etant vide" & vbTab & vbTab & ": " & ValVide & vbCrLf _
& vbTab & "Cellule Ayant du Texte" & vbTab & ": " & ValText & vbCrLf _
& vbTab & "Cellule Valeur Numérique" & vbTab & ": " & ValNume & vbCrLf _
& vbTab & "Cellule Avec Formule" & vbTab & ": " & ValForm & vbCrLf _
& vbTab & "Cellule Etant en Erreur" & vbTab & ": " & ValErre & vbCrLf _
& vbTab & "Cellule Format Conditionnel" & vbTab & ": " & ValCond & vbCrLf _
& vbTab & "Cellule Avec Commentaire" & vbTab & ": " & ValComm & vbCrLf _
& vbTab & "Cellule Critère de validation" & vbTab & ": " & ValVali & vbCrLf _
& vbTab & "Cellule Visible" & vbTab & vbTab & ": " & valVisi & vbCrLf


End Sub

Bonne Soirée
@+Thierry
 

Discussions similaires

Réponses
10
Affichages
454

Statistiques des forums

Discussions
312 323
Messages
2 087 301
Membres
103 512
dernier inscrit
sisi235