XL 2013 comment Identifier le type Rows où columns

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

patricktoulon

XLDnaute Barbatruc
bonjour à tous
comment peut on identifier le type Rows ou Columns avec un argument rows ou columns
j'explique
j'ai une fonction dans la quelle j'injecte un argument rng.rows ou rng .columns
je voudrais identifier le type d'object et non "Range"

VB:
Sub test()
Dim rng As Range

Set rng = [A1:A20]
mafiontion rng, rng.Rows

Set rng = [A1:H10]
mafiontion rng, rng.Columns
End Sub

Function mafonction(r As Range, RowColumns)
MsgBox TypeName(RowColumns)
End Function
 
Solution
donc si je ne veux pas intégrer ces deux lignes dans une fonction
je me fait une fonction perso
VB:
Sub test()
    Dim rng As Range
    '-----------------------------------------
    Set rng = [A1:A10]
    MsgBox GetTypeRange(rng.Rows)

    Set rng = [A1:A10]
    MsgBox GetTypeRange(rng.Columns)
'-----------------------------------------
    Set rng = [A1:J1]
   MsgBox GetTypeRange(rng.Rows)

    Set rng = [A1:J1]
     MsgBox GetTypeRange(rng.Columns)
 '-----------------------------------------
    Set rng = [A1:J10]
    MsgBox GetTypeRange(rng.Rows)

    Set rng = [A1:J10]
     MsgBox GetTypeRange(rng.Columns)
End Sub

Function GetTypeRange(Rowcolumns As Range)
 Dim X As Boolean
 X = Rowcolumns(1).Address = Rowcolumns.Rows(1).Address...
oui mais elle n'avait pas tout juste dans les autres cas

un truc un peu téléphoné
mais ça m'oblige à avoir 2 arguments
VB:
Sub test()
    Dim rng As Range
    Set rng = [A1:A10]
    MsgBox GetTypeRange(rng)
    '-----------------------------------------
    Set rng = [A1:A10]
    MsgBox GetTypeRange(rng, rng.Rows)

    Set rng = [A1:A10]
    MsgBox GetTypeRange(rng, rng.Columns)
    '-----------------------------------------
    Set rng = [A1:J1]
    MsgBox GetTypeRange(rng, rng.Rows)

    Set rng = [A1:J1]
    MsgBox GetTypeRange(rng, rng.Columns)
    '-----------------------------------------
    Set rng = [A1:J10]
    MsgBox GetTypeRange(rng, rng.Rows)

    Set rng = [A1:J10]
    MsgBox GetTypeRange(rng, rng.Columns)
End Sub

Function GetTypeRange(rng As Range, Optional Rowcolumns As Range)
    Dim X As Long
    If Rowcolumns Is Nothing Then GetTypeRange = "Range": Exit Function
    X = Abs(Rowcolumns(1).Address = Rowcolumns.Rows(1).Address)
    GetTypeRange = Array("column", "Row", "Range")(X)
End Function
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
3
Affichages
582
Réponses
0
Affichages
964
Retour