[Résolu] Selection de tableaux

Selection de tableaux [Résolu] - VB/VBA/VBS - Programmation

Marsh Posté le 29-10-2005 à 10:38:51    

Bonjour,
 
J'ai 4 tableaux identiques sur une meme feuille. J'aimerai pouvoir les selectionner à loisir pour pouvoir refaire la mise en forme automatiquement quand cela est necessaire.
 
Mon problème est le suivant : comment dire à Excel de selectionner le tableau 2 ou le tableau 4 par exemple ?
 
Je suis sous Excel97.
 
Merci d'avance.


Message édité par Be_Aware le 02-11-2005 à 15:42:28
Reply

Marsh Posté le 29-10-2005 à 10:38:51   

Reply

Marsh Posté le 29-10-2005 à 14:44:20    

selectionner le 1er tableau puis faire Insertion / Nom / Définir ...Tablo1 par exemple.
La même chose pour Tablo2, Tablo3...
Ensuite :

Code :
  1. Sub test()
  2. Range("Tablo1" ).Select
  3. End Sub


A+


---------------
roger
Reply

Marsh Posté le 29-10-2005 à 15:47:20    

Citation :

selectionner le 1er tableau puis faire Insertion / Nom / Définir ...Tablo1 par exemple.  
La même chose pour Tablo2, Tablo3...  
Ensuite :  
 
 
Code :
 
Sub test()  
Range("Tablo1" ).Select  
End Sub
 
 
 
A+


 
Merci de ta réponse.
 
Mais comment faire pour appliquer les mêmes modifications de formats quelque soit la plage selectionnée ?
 
Je vais essayer de m'expliquer plus clairement :
 
Admettons 2 tableaux. L'un en A7:I40 et l'autre en A77:I109. Ces deux tableaux vont se retrouver "malmener" lors de saisies (le quadrillage va être modifié, les cellules fusionner, les bodures effacées etc, etc), comment faire donc pour que lorsque je lance ma macro, Excel me modifie le bon tableau ? Là j'arrive à remettre le 1er tableau en état mais impossible d'atteindre le second tableau...
 
Merci de m'aider, je galère pas mal...
 

Code :
  1. Sub Macro1()
  2.     Range("A7:I40" ).Select
  3.     selection.Borders(xlDiagonalDown).LineStyle = xlNone
  4.     selection.Borders(xlDiagonalUp).LineStyle = xlNone
  5.     With selection.Borders(xlEdgeLeft)
  6.         .LineStyle = xlContinuous
  7.         .Weight = xlThin
  8.         .ColorIndex = xlAutomatic
  9.     End With
  10.     With selection.Borders(xlEdgeTop)
  11.         .LineStyle = xlContinuous
  12.         .Weight = xlThin
  13.         .ColorIndex = xlAutomatic
  14.     End With
  15.     With selection.Borders(xlEdgeBottom)
  16.         .LineStyle = xlContinuous
  17.         .Weight = xlThin
  18.         .ColorIndex = xlAutomatic
  19.     End With
  20.     With selection.Borders(xlEdgeRight)
  21.         .LineStyle = xlContinuous
  22.         .Weight = xlThin
  23.         .ColorIndex = xlAutomatic
  24.     End With
  25.     With selection.Borders(xlInsideVertical)
  26.         .LineStyle = xlContinuous
  27.         .Weight = xlThin
  28.         .ColorIndex = xlAutomatic
  29.     End With
  30.     With selection.Borders(xlInsideHorizontal)
  31.         .LineStyle = xlContinuous
  32.         .Weight = xlThin
  33.         .ColorIndex = xlAutomatic
  34.     End With
  35.     Range("A7:A12" ).Select
  36.     selection.Borders(xlDiagonalDown).LineStyle = xlNone
  37.     selection.Borders(xlDiagonalUp).LineStyle = xlNone
  38.     selection.Borders(xlEdgeLeft).LineStyle = xlNone
  39.     selection.Borders(xlEdgeTop).LineStyle = xlNone
  40.     selection.Borders(xlEdgeBottom).LineStyle = xlNone
  41.     selection.Borders(xlEdgeRight).LineStyle = xlNone
  42.     selection.Borders(xlInsideVertical).LineStyle = xlNone
  43.     selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  44.     Range("B7:I8" ).Select
  45.     With selection
  46.         .HorizontalAlignment = xlCenter
  47.         .VerticalAlignment = xlCenter
  48.         .WrapText = True
  49.         .Orientation = 0
  50.         .ShrinkToFit = False
  51.         .MergeCells = True
  52.     End With
  53.     Range("A13:A40" ).Select
  54.     selection.Borders(xlDiagonalDown).LineStyle = xlNone
  55.     selection.Borders(xlDiagonalUp).LineStyle = xlNone
  56.     With selection.Borders(xlEdgeLeft)
  57.         .LineStyle = xlContinuous
  58.         .Weight = xlMedium
  59.         .ColorIndex = xlAutomatic
  60.     End With
  61.     With selection.Borders(xlEdgeTop)
  62.         .LineStyle = xlContinuous
  63.         .Weight = xlMedium
  64.         .ColorIndex = xlAutomatic
  65.     End With
  66.     With selection.Borders(xlEdgeBottom)
  67.         .LineStyle = xlContinuous
  68.         .Weight = xlMedium
  69.         .ColorIndex = xlAutomatic
  70.     End With
  71.     With selection.Borders(xlEdgeRight)
  72.         .LineStyle = xlContinuous
  73.         .Weight = xlMedium
  74.         .ColorIndex = xlAutomatic
  75.     End With
  76.     With selection.Borders(xlInsideHorizontal)
  77.         .LineStyle = xlContinuous
  78.         .Weight = xlThin
  79.         .ColorIndex = xlAutomatic
  80.     End With
  81.     Range("B7:I40" ).Select
  82.     selection.Borders(xlDiagonalDown).LineStyle = xlNone
  83.     selection.Borders(xlDiagonalUp).LineStyle = xlNone
  84.     With selection.Borders(xlEdgeLeft)
  85.         .LineStyle = xlContinuous
  86.         .Weight = xlMedium
  87.         .ColorIndex = xlAutomatic
  88.     End With
  89.     With selection.Borders(xlEdgeTop)
  90.         .LineStyle = xlContinuous
  91.         .Weight = xlMedium
  92.         .ColorIndex = xlAutomatic
  93.     End With
  94.     With selection.Borders(xlEdgeBottom)
  95.         .LineStyle = xlContinuous
  96.         .Weight = xlMedium
  97.         .ColorIndex = xlAutomatic
  98.     End With
  99.     With selection.Borders(xlEdgeRight)
  100.         .LineStyle = xlContinuous
  101.         .Weight = xlMedium
  102.         .ColorIndex = xlAutomatic
  103.     End With
  104. End Sub


Message édité par Be_Aware le 29-10-2005 à 15:48:44
Reply

Marsh Posté le 29-10-2005 à 18:07:19    

bonsoir,
Tu n'as pas besoin de tout redéfinir tu fais un Copier / Collage Spécial + Format ça devrait suffire.
 
Moi j'ai défini (Insertion / Nom / Définir) ton Tablo de Départ  comme suit :
 
Tablo fait référence à : =Feuil1!$A$7:$I$40  (tout le tableau)
 
Il faut mieux définir tes tableaux cibles par leur angle supérieur gauche.
Cible1 fait référence à =Feuil1!$A$77
Cible2 fait référence à =Feuil1!$A$147
Cible3 fait référence à =Feuil1!$A$217
 
Ensuite :

Code :
  1. Sub Test()
  2. Range("Tablo" ).Copy
  3.     Range("Cible1" ).PasteSpecial Paste:=xlPasteFormats
  4.     Range("Cible2" ).PasteSpecial Paste:=xlPasteFormats
  5.     Range("Cible3" ).PasteSpecial Paste:=xlPasteFormats
  6. End Sub


Attention ! Les cellules fusionnées sont à proscrire (ou à tout le moins très déconseillées) pour les macros. Risques de plantage.  
Dans 99 % des cas des solutions de contournement sont possible...
Si tu veux mettre un titre à ton tableau, il vaut mieux le mettre sur une seule ligne en B7 (la hauteur de la ligne s'adaptera à la taille de tes caractères)
ensuite tu Sélectionnes B7:I7 et tu fait Format / Cellules / Onglet Alignement + Choisir Horizontal + Centré sur plusieurs colonnes
Bon courage.
A+


---------------
roger
Reply

Marsh Posté le 02-11-2005 à 15:41:16    

Merci !
 
Ton aide m'a été précieuse et en suivant tes conseils je m'en suis sortis :)
 

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed