Fusion cellules par macro

breitzou

XLDnaute Occasionnel
Bonsoir le forum,:)

je travaille sur la mise en place d'un planning hebdomadaire, et l'une des dernières choses qu'il me reste à faire, c'est la mise en place d'un bouton de commande qui me permettrait de pouvoir effectuer des fusions de cellules que j'aurais préalablement sélectionnées avec la souris.

Je suis allé voir beaucoup d'anciens messages qui expliquent plein de possibilités de fusion. Mais je n'ai pas trouvé le plus simple, à savoir ma requête ci-dessus !!!:D

J'ai mis le fichier en PJ. J'espère avoir été assez explicite. Tout est réexpliqué dans l'onglet appelé "38" du fichier.

Merci d'avance pour votre aide.;)

Breitzou
 

Pièces jointes

  • Planning hebsports.zip
    45.6 KB · Affichages: 32

JNP

XLDnaute Barbatruc
Re : Fusion cellules par macro

Salut Breitzou, ça faisait un bail :),
Pourquoi pas tout simplement
Code:
[COLOR=blue]Private Sub[/COLOR] Annuler_Click()
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Rouge_Click()
ActiveCell.Interior.ColorIndex = 22
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Bleu_Click()
ActiveCell.Interior.ColorIndex = 17
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Vert_Click()
ActiveCell.Interior.ColorIndex = 14
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Jaune_Click()
ActiveCell.Interior.ColorIndex = 36
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Orange_Click()
ActiveCell.Interior.ColorIndex = 40
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Rose_Click()
ActiveCell.Interior.ColorIndex = 38
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
[COLOR=blue]Private Sub[/COLOR] Gris_Click()
ActiveCell.Interior.ColorIndex = 16
Selection.Merge
Unload USF1
[COLOR=blue]End Sub[/COLOR]
Bonne nuit :cool:
 

breitzou

XLDnaute Occasionnel
Re : Fusion cellules par macro

Salut JNP,:)

comme d'habitude, tu apportes la solution à mon problème et je t'en remercie une fois de plus.:)
J'ai encore appris quelque chose aujourd'hui avec "selection.merge".
En revanche, je ne connais pas le terme en VBA qui permet de centrer le contenu fusionné (ce que je souhaiterais rajouter dans le code que tu m'as renvoyé!!!);)

Merci encore de ton aide

Breitzou
 

breitzou

XLDnaute Occasionnel
Re : Fusion cellules par macro

Re:)

Stop à tous,:)
Stop JNP:D

c'est bon, j'ai la phrase magique!!!:p

Cela fonctionne mais peux-tu me dire si c'est vraiment OK :

Private Sub Annuler_Click()
Unload USF1
End Sub
Private Sub Rouge_Click()
ActiveCell.Interior.ColorIndex = 22
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub
Private Sub Bleu_Click()
ActiveCell.Interior.ColorIndex = 17
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub
Private Sub Vert_Click()
ActiveCell.Interior.ColorIndex = 14
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub
Private Sub Jaune_Click()
ActiveCell.Interior.ColorIndex = 36
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub
Private Sub Orange_Click()
ActiveCell.Interior.ColorIndex = 40
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub
Private Sub Rose_Click()
ActiveCell.Interior.ColorIndex = 38
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub
Private Sub Gris_Click()
ActiveCell.Interior.ColorIndex = 16
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub


Merci encore et bonne soirée:)

Breitzou
 

Staple1600

XLDnaute Barbatruc
Re : Fusion cellules par macro

Bonsoir


Une façon pour alléger un peu
Code:
Private Sub Annuler_Click()
Unload USF1
End Sub
Private Sub Rouge_Click()
mef 22
End Sub
Private Sub Bleu_Click()
mef 17
End Sub
Private Sub Vert_Click()
mef 14
End Sub
Private Sub Jaune_Click()
mef 36
End Sub
Private Sub Orange_Click()
mef 40
End Sub
Private Sub Rose_Click()
mef 38
End Sub
Private Sub Gris_Click()
mef 16
End Sub
Et dans un module standard
Code:
Public Sub mef(cc As Long)
ActiveCell.Interior.ColorIndex = cc
Selection.Merge
Selection.HorizontalAlignment = xlCenter
Unload USF1
End Sub

PS: dans le code de la feuille, j'ajouterai ceci
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Selection.Columns.Count = 256 Or Selection.Rows.Count = 65536 Then End
USF1.Show
End Sub
 
Dernière édition:

Membres actuellement en ligne

Statistiques des forums

Discussions
312 084
Messages
2 085 194
Membres
102 810
dernier inscrit
mohammedaminelahbali