Simplifier la facon de conditionner des variables

  • Initiateur de la discussion Thomas
  • Date de début
T

Thomas

Guest
Bonjour le Forum,

dans ma macro, je dois conditionner mes variable,

mais le facteur commun est la ligne.

afin de diminuer la saisie de ces condition, est il possible d'utilider le dénominateur comun.

If Adres = Cells(23, 23) Then Postal = Cells(23, 24)
If Adres = Cells(23, 26) Then Postal = Cells(23, 24)
If Adres = Cells(24, 26) Then Postal = Cells(24, 24)
If Adres = Cells(24, 23) Then Postal = Cells(24, 24)
If Adres = Cells(25, 26) Then Postal = Cells(25, 24)
If Adres = Cells(25, 23) Then Postal = Cells(25, 24)
If Adres = Cells(26, 26) Then Postal = Cells(26, 24)
If Adres = Cells(26, 23) Then Postal = Cells(26, 24)
If Adres = Cells(23, 23) Then Pays = Cells(23, 22)
If Adres = Cells(23, 26) Then Pays = Cells(23, 22)
If Adres = Cells(24, 23) Then Pays = Cells(24, 22)
If Adres = Cells(24, 26) Then Pays = Cells(24, 22)
If Adres = Cells(25, 23) Then Pays = Cells(25, 22)
If Adres = Cells(25, 26) Then Pays = Cells(25, 22)
If Adres = Cells(26, 26) Then Pays = Cells(26, 22)
If Adres = Cells(26, 23) Then Pays = Cells(26, 22)

ma vision des choses serait plus du

If Adres = Cells (23, *) Then Postal = Cells (23, 24) & Pays = Cells(23, 22)

enfin un moyen de dire une fois si adres=... alors postal= et Pays =

D'avance merci
 

Abel

XLDnaute Accro
Bonjour Thomas,

Si la variable 'Adres' est définie comme une plage (Dim Adres as Range ou Public/Private Adres as Range) alors essaie :

If Adres.Row = 23 then blabla
If Adres.Row = ...

Tu peux essayer aussi Select Case

Select Case Adres.Row

Case 23
blabla ce qu'il faut faire

End Case

En espérant que cela te dépanne.

Abel.
 

Discussions similaires

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
314 017
Messages
2 104 584
Membres
109 084
dernier inscrit
mizab