Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

erreur range

6 réponses
Avatar
Hus Christian
Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la
colonne de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide

6 réponses

Avatar
papou
Bonjour
Quel le résultat attendu par ta variable r, as-tu vérifié ?
Il me semble que tu utilises une référence de style [A2].
Dans ce cas l'expression Range(r) ne fonctionnera pas et c'est normal.
Si tu tiens à conserver le style de référence entre crochets, alors tu dois
utiliser quelque chose comme :
For Each c in r

Cordialement
PAscal

"Hus Christian" a écrit dans le
message de news:
Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la
colonne de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide




Avatar
Piotr
Bonjour,

Je me trompe peut-être, mais j'ai l'impression qu'il suffirait de mettre
col = Mid(ActiveCell.Address, 1, 1)
pour récupérer le caractère de la colonne et non pas le chiffre de la ligne.
NB : cette fonction ne marche qu'avec les colonne à 1 lettre. dès que tu en
auras 2 (AA, AB, etc.), cela ne te sélectionnera que la première. Il y a une
fonction qui permet de passer de références L1C1 en A1, mais je ne m'en
souviens plus.
Quelqu'un pour aider à généraliser la formule ?

Piotr.

"Hus Christian" a écrit dans le
message de news:
Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la
colonne de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide




Avatar
Hus Christian
Bonjour papou et merci
J'essaye avec r d'avoir ([A2], [A65000].End(xlUp)).
dans l'exemple de JB, j'ai essayé en remplaçnat les guillements par les
crochets et ça marche.
Par contre, en remplaçanr range(r) par r , j'ai une erreur



Le 30/10/2007, Hus Christian a supposé :
Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la colonne
de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide


Avatar
Hus Christian
Bonjour Piotr et merci

Je ne peux pas utiliser Mid(ActiveCell.Address, 1, 1) car le format de
Activecell.Adress est $A$1, donc je prends à partir du deuxième
caractère.
Comme je travail sur le 15 premiére colonnes maximum ça me suffit

Le 30/10/2007, Hus Christian a supposé :
Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la colonne
de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide


Avatar
MichDenis
Sub Test()

Dim Col As String
Dim R As Range, C As Range
Dim MonDico As Object

Col = Split(ActiveCell.Address, "$")(1)

Set R = Range(Cells(2, "" & Col & _
""), Cells(65536, "" & Col & "").End(xlUp))
On Error Resume Next
Set MonDico = CreateObject("Scripting.Dictionary")

For Each C In R.SpecialCells(xlCellTypeVisible)
If Not MonDico.Exists(C.Value) Then
MonDico.Add C.Value, C.Value
End If
Next C
MsgBox MonDico.Count

End Sub




"Hus Christian" a écrit dans le message de news:

Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la
colonne de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide
Avatar
Hus Christian
Merci beaucoup
Ca marche impécablement
J'avais bien essayé les guillemets mais pas avec cells
Encore merci pour ce forum vraiment super


MichDenis avait soumis l'idée :
Sub Test()

Dim Col As String
Dim R As Range, C As Range
Dim MonDico As Object

Col = Split(ActiveCell.Address, "$")(1)

Set R = Range(Cells(2, "" & Col & _
""), Cells(65536, "" & Col & "").End(xlUp))
On Error Resume Next
Set MonDico = CreateObject("Scripting.Dictionary")

For Each C In R.SpecialCells(xlCellTypeVisible)
If Not MonDico.Exists(C.Value) Then
MonDico.Add C.Value, C.Value
End If
Next C
MsgBox MonDico.Count

End Sub




"Hus Christian" a écrit dans le
message de news:
Bonjour
Encore merci à JB pour ça macro,j'essaye de l'adapter pour compter la
colonne de la cellule active.
l'original de JB

Set mondico = CreateObject("Scripting.Dictionary")
For Each c In
Range("A2",[A65000].End(xlUp)).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

la modif qui plante
Set mondico = CreateObject("Scripting.Dictionary")
col = Mid(ActiveCell.Address, 2, 1)
r = "[" & col & "2], [" & col & "65000].End(xlUp)"
For Each c In Range(r).SpecialCells(xlCellTypeVisible)
If Not mondico.Exists(c.Value) Then mondico.Add c.Value, c.Value
Next c
MsgBox mondico.Count

Merci de votre aide