bonjour,
je souhaite colorier la diagonale d'une plage sélectionnée sous Excel dans le cas où cette plage est carrée mais je rencontre un problème quand je cherche à récupérer les coordonnées de la case en haut à gauche de la selection...
la fonction est_carree fonctionne très bien..
Pourriez-vous m'aider s'il vous plait !??
Merci à tous
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Function est_carree(plage As Range) As Boolean Dim nbcol As Integer Dim nblig As Integer nbcol = plage.Columns.Count nblig = plage.Rows.Count est_carree = (nbcol = nblig) End Function Sub diago_perso() Dim i As Integer Dim j As Integer Dim nbcol As Integer Dim haut As Integer Dim gauche As Integer Dim kase As Range nbcol = Selection.Rows.Count MsgBox ("nbcol: " & nbcol) kase = Selection.End(xlTop).End(xlToLeft).Select haut = kase.Row MsgBox ("haut: " & haut) gauche = Selection.End(xlToLeft) If (est_carree(Selection) = True) Then For i = gauche To nbcol For j = haut To nbcol Range(Cells(i, j)).Interior.ColorIndex = 3 j = j + nbcol Next j i = i + nbcol Next i Else MsgBox ("La sélection n'est pas carrée") End If End Sub
Partager