• Initiateur de la discussion Initiateur de la discussion OlivGM
  • Date de début Date de début

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 !

OlivGM

XLDnaute Occasionnel
Bonjour,

Comment écrire une suite descendante de nombres (col A) en colimaçon à partir d'un point central nommé en B1?

Merci de votre solution. (petit exemple)

a+
 

Pièces jointes

Re : listage

Hello

Avec ce code.....
Code:
Sub spirale()


fin = Range("A65536").End(xlUp).Row
'on force pour les 3 premiers éléments
AdDépart = Range("B1")
Range(AdDépart).CurrentRegion.Clear
Range(AdDépart) = [A1].Value

from = AdDépart
Range(from).Select

Range(from).Offset(0, -1) = [A2]
from = Range(from).Offset(0, -1).Address

Range(from).Offset(-1, 0) = [A3]
from = Range(from).Offset(-1, 0).Address

'pour i de 3 jusqu'à fin
For i = 4 To fin
    'dispo à gauche et non vide au dessus (=changement de direction)
    verslagauche = Range(from).Offset(0, -1) = "" And Range(from).Offset(-1, 0) <> ""
    'dispo à droite et non vide en dessous (=changement de direction)
    versladroite = Range(from).Offset(0, 1) = "" And Range(from).Offset(1, 0) <> ""
    'dispo en bas et non vide à gauche (=changement de direction)
    verslebas = Range(from).Offset(1, 0) = "" And Range(from).Offset(0, -1) <> ""
    'dispo en haut et non vide à droite(=changement de direction)
    verslehaut = Range(from).Offset(-1, 0) = "" And Range(from).Offset(0, 1) <> ""
    
    If versladroite Then
        verslehaut = False
        verslagauche = False
        Range(from).Offset(0, 1) = Range("A" & i)
        from = Range(from).Offset(0, 1).Address
    ElseIf verslebas Then
        verslehaut = False
        versladroite = False
        Range(from).Offset(1, 0) = Range("A" & i)
        from = Range(from).Offset(1, 0).Address
        
        'MsgBox "bas"
    ElseIf verslagauche Then
        Range(from).Offset(0, -1) = Range("A" & i)
        from = Range(from).Offset(0, -1).Address
        'MsgBox "gauche"
    ElseIf verslehaut Then
        Range(from).Offset(-1, 0) = Range("A" & i)
        from = Range(from).Offset(-1, 0).Address
        'MsgBox "haut"
    
    End If
Next i

End Sub
 
Re : listage

Bonjour à tous,
ceci pour le fun
je me suis piqué sur ce truc sans queue ni tête
Bruno
Code:
Sub spirale()
lig = 11: col = 11
[c2:z30].ClearContents
n = [A65000].End(3).Row
debut:
'bas
For k = lig + 1 To 24
i = i + 1: Cells(k, col) = Cells(i, 1)
If i = n Then Exit Sub
If Cells(k, col - 1) = "" Then lig = k: Exit For
Next
'gauche
For k = col - 1 To 2 Step -1
i = i + 1: Cells(lig, k) = Cells(i, 1)
If i = n Then Exit Sub
If Cells(lig - 1, k) = "" Then col = k: Exit For
Next
'haut
For k = lig - 1 To 1 Step -1
i = i + 1: Cells(k, col) = Cells(i, 1)
If i = n Then Exit Sub
If Cells(k, col + 1) = "" Then lig = k: Exit For
Next
'droite
For k = col + 1 To 25
i = i + 1: Cells(lig, k) = Cells(i, 1)
If i = n Then Exit Sub
If Cells(lig + 1, k) = "" Then col = k: Exit For
Next
GoTo debut
End Sub
 
Re : listage

bonjour , youky

Ya un schimil........

20151124-094523-001.jpg
 
- 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
4
Affichages
262
Réponses
7
Affichages
291
Réponses
16
Affichages
476
Réponses
19
Affichages
701
  • Question Question
Microsoft 365 Remplissage auto
Réponses
14
Affichages
250
Réponses
16
Affichages
415
Retour