Adresse d'une valeur dans une MsgBox

BChaly

XLDnaute Occasionnel
Bonsoir à tous,

Le code suivant fonctionne très bien pour trouver l'adresse d'une valeur dans une MsgBox.

Comment puis-je modifier ce code pour supprimer l'adresse des cellules vides?
(Supprimer la 1ere ligne du message dans mon exemple)

Merci pour votre aide.

Cordialement,

BChaly

Code:
Option Explicit

Sub AdresseValeur()
 
Dim D1, D2 As Object
Dim V1, V2 As Variant
Dim K1 As Variant
Dim Rge As Range
Dim i As Integer
Dim No, Address As String
 
Set D1 = CreateObject("Scripting.Dictionary")
Set D2 = CreateObject("Scripting.Dictionary")
Set Rge = Range([B1], Range("B" & Rows.Count).End(xlUp))

    For i = 1 To Rge.Count
        No = Rge(i) & " " & Rge(i).Offset(0, 1)
                If D1.exists(No) = True Then
                D1.Add No, No
                    Else
            If D2.exists(No) = False Then
                D2.Add No, Rge(i).Address(0, 0)
                    Else
                D2(No) = D2(No) & "; " & Rge(i).Address(0, 0)
            End If
            End If
    Next i
   
V1 = D2.Items
K1 = D2.keys
     
    For i = 0 To D2.Count - 1
        V2 = V2 & K1(i) & " se trouve dans la cellule " & V1(i) & vbCrLf
    Next i
 
MsgBox V2
    
End Sub
 

Pièces jointes

  • Adresse_Valeur.xls
    40 KB · Affichages: 40
Dernière édition:

xhudi69

XLDnaute Accro
Re : Adresse d'une valeur dans une MsgBox

Bonjour BChaly, le Forum,
Bonjour pierrejean :)

Ou alors ceci:
Code:
Sub AdresseValeur()
 
Dim D1, D2 As Object
Dim V1, V2 As Variant
Dim K1 As Variant
Dim Rge As Range
Dim i As Integer
Dim No, Address As String
 
Set D1 = CreateObject("Scripting.Dictionary")
Set D2 = CreateObject("Scripting.Dictionary")
Set Rge = Range([B1], Range("B" & Rows.Count).End(xlUp))

    For i = 1 To Rge.Count
        No = Rge(i) & " " & Rge(i).Offset(0, 1)
        If Rge(i) <> "" Then '=========================================
            If D1.exists(No) = True Then
                D1.Add No, No
                    Else
            If D2.exists(No) = False Then
                D2.Add No, Rge(i).Address(0, 0)
                    Else
                D2(No) = D2(No) & "; " & Rge(i).Address(0, 0)
            End If
            End If
        End If '========================================================
    Next i
   
V1 = D2.Items
K1 = D2.keys
    For i = 0 To D2.Count - 1
        V2 = V2 & K1(i) & " se trouve dans la cellule " & V1(i) & vbCrLf
    Next i
MsgBox V2
End Sub

@+ :cool:
 

Discussions similaires

Statistiques des forums

Discussions
312 508
Messages
2 089 138
Membres
104 047
dernier inscrit
bravetta