Selection plage de données avec des variables
Résolu/Fermé
A voir également:
- Selection plage de données avec des variables
- Effacer les données de navigation - Guide
- Reinstaller windows sans perte de données - Guide
- Frédéric cherche à faire le buzz sur les réseaux sociaux. il a ajouté une image de manchots sur une image de plage. retrouvez l'image originale de la plage. que cachent les manchots ? - Forum Graphisme
- Outil selection illustrator ne fonctionne pas ✓ - Forum Illustrator
- Service de diffusion de données - Forum TNT / Satellite / Réception
9 réponses
eriiic
Messages postés
24569
Date d'inscription
mardi 11 septembre 2007
Statut
Contributeur
Dernière intervention
28 décembre 2023
7 212
8 déc. 2007 à 14:44
8 déc. 2007 à 14:44
Bonjour,
Si, bien sûr tu peux utiliser des variables
Voici un exemple:
eric
Si, bien sûr tu peux utiliser des variables
Voici un exemple:
Sub selectionner() Dim table() lig = 8 col = 0 nblig = 3 nbcol = 2 'sélectionner [A1].Offset(lig, col).Resize(nblig, nbcol).Select ' valeurs dans table(lig,col) (indices commencent à 1) table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value End Sub
eric
eriiic
Messages postés
24569
Date d'inscription
mardi 11 septembre 2007
Statut
Contributeur
Dernière intervention
28 décembre 2023
7 212
9 déc. 2007 à 23:57
9 déc. 2007 à 23:57
Je ne sais pas quelle est ta sélection de départ.
Avec ce que tu mets tu devrais démarrer avec A22 de sélectionné...
si c'est autre chose adapte, par exemple si A35 et une variable i = 35
Range("A" & i & ":I" & i)
le & te concatene 2 chaines de caracteres ou 1 chaine et un nombre ici en l'occurence
Avec ce que tu mets tu devrais démarrer avec A22 de sélectionné...
si c'est autre chose adapte, par exemple si A35 et une variable i = 35
Range("A" & i & ":I" & i)
le & te concatene 2 chaines de caracteres ou 1 chaine et un nombre ici en l'occurence
Merci Eriiic,
J'ai recopié ton morceau de code, cependant, un problème se pose encore...
Ainsi, je ne peux pas enchaîner plusieurs fois cette opération, c'est-à-dire :
J'utilise ton code pour sélectionner la plage dont j'ai besoin
Je fais les opérations sur la plage sélectionnée
J'incrémente les variables (lig, col, nblig, nbcol) de manière à sélectionner une nouvelle plage de cellules
Je réutilise ton code avec les nouvelles variables et a ce moment là,
Erreur d'exécution '1004':
Erreur définie parl'application ou par l'objet
Ensuite, je fais débogage et il m'indique cette ligne
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
Merci de me répondre...
Je peux aussi te poster tout le code si ça te convient mieux...
J'ai recopié ton morceau de code, cependant, un problème se pose encore...
Ainsi, je ne peux pas enchaîner plusieurs fois cette opération, c'est-à-dire :
J'utilise ton code pour sélectionner la plage dont j'ai besoin
Je fais les opérations sur la plage sélectionnée
J'incrémente les variables (lig, col, nblig, nbcol) de manière à sélectionner une nouvelle plage de cellules
Je réutilise ton code avec les nouvelles variables et a ce moment là,
Erreur d'exécution '1004':
Erreur définie parl'application ou par l'objet
Ensuite, je fais débogage et il m'indique cette ligne
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
Merci de me répondre...
Je peux aussi te poster tout le code si ça te convient mieux...
eriiic
Messages postés
24569
Date d'inscription
mardi 11 septembre 2007
Statut
Contributeur
Dernière intervention
28 décembre 2023
7 212
9 déc. 2007 à 22:35
9 déc. 2007 à 22:35
Bonsoir,
oui, c'est mieux avec le code.
Mais c'était un exemple seulement tu sais...
oui, c'est mieux avec le code.
Mais c'était un exemple seulement tu sais...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Bon voila, alors dans ce projet je gère un championnat de football, et dans ce code, je cherche à créer un nouveau championnat à partir de 2 feuilles types (cette copie ça marche). Mais ensuite je cherche a créer dans la 1ère feuille (Tables des matières) un résumé du championnat que je suis en train de créer... C'est pourquoi, j'ai besoin de modifier la plage de données pour y effectuer toutes les opérations de mises en forme (que j'ai récupérer grace à une macro)...
Si vous ne comprenez pas quoique ce soit n'hésitez pas...
En espérant que vous pourrez m'aidez
Private Sub CommandButton2_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim champ As String
Dim table()
Dim lig As Integer
Dim col As Integer
Dim nblig As Integer
Dim nbcol As Integer
i = Sheets.Count
'On va créer 2 nouvelles feuilles
Sheets(2).Select
Sheets(2).Copy After:=Sheets(i)
Sheets(i + 1).Name = TextBox1
Sheets(i + 1).Range("A1") = TextBox1
Sheets(i + 1).Range("A10") = "Liste des équipes participants à la " & TextBox1
For i = 100 To 111
Cells(i, 1) = ""
Next
i = Sheets.Count
Sheets(3).Select
Sheets(3).Copy After:=Sheets(i)
Sheets(i + 1).Name = "Résultats - " & TextBox1
Sheets(1).Select
champ = TextBox1
i = (Sheets.Count - 1) / 2
k = 0
For j = 1 To i
k = k + 7
Next
lig = k
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
lig = k + 1
col = 0
nblig = 1
nbcol = 0
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
'ActiveCell.FormulaR1C1 = "='" & champ & "'!R[19]C"
nblig = 1
nbcol = 3
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.AutoFill Destination:=Range("cel1:cel2"), Type:=xlFillDefault
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.AutoFill Destination:=Range("A15:I18"), Type:=xlFillDefault
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k - 1
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k + 1
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k + 1
col = 0
nblig = 3
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k - 2
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
champ & "!A1", TextToDisplay:=champ
NouveauChampionnat.Hide
Championnat.Show
End Sub
Si vous ne comprenez pas quoique ce soit n'hésitez pas...
En espérant que vous pourrez m'aidez
Private Sub CommandButton2_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim champ As String
Dim table()
Dim lig As Integer
Dim col As Integer
Dim nblig As Integer
Dim nbcol As Integer
i = Sheets.Count
'On va créer 2 nouvelles feuilles
Sheets(2).Select
Sheets(2).Copy After:=Sheets(i)
Sheets(i + 1).Name = TextBox1
Sheets(i + 1).Range("A1") = TextBox1
Sheets(i + 1).Range("A10") = "Liste des équipes participants à la " & TextBox1
For i = 100 To 111
Cells(i, 1) = ""
Next
i = Sheets.Count
Sheets(3).Select
Sheets(3).Copy After:=Sheets(i)
Sheets(i + 1).Name = "Résultats - " & TextBox1
Sheets(1).Select
champ = TextBox1
i = (Sheets.Count - 1) / 2
k = 0
For j = 1 To i
k = k + 7
Next
lig = k
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
lig = k + 1
col = 0
nblig = 1
nbcol = 0
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
'ActiveCell.FormulaR1C1 = "='" & champ & "'!R[19]C"
nblig = 1
nbcol = 3
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.AutoFill Destination:=Range("cel1:cel2"), Type:=xlFillDefault
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.AutoFill Destination:=Range("A15:I18"), Type:=xlFillDefault
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k - 1
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k + 1
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k + 1
col = 0
nblig = 3
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
lig = k - 2
col = 0
nblig = 1
nbcol = 9
'sélectionner
[A1].Offset(lig, col).Resize(nblig, nbcol).Select
' valeurs dans table(lig,col) (indices commencent à 1)
table = [A1].Offset(lig, col).Resize(nblig, nbcol).Value
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
champ & "!A1", TextToDisplay:=champ
NouveauChampionnat.Hide
Championnat.Show
End Sub
eriiic
Messages postés
24569
Date d'inscription
mardi 11 septembre 2007
Statut
Contributeur
Dernière intervention
28 décembre 2023
7 212
9 déc. 2007 à 23:01
9 déc. 2007 à 23:01
nbcol = 0
ta sélection doit fazire au moins 1 ligne et une colonne
et supprime toutes les lignes
ta sélection doit fazire au moins 1 ligne et une colonne
et supprime toutes les lignes
valeurs dans table(lig,col) (indices commencent à 1) table = [A1].Offset(lig, col).Resize(nblig, nbcol).Valuetu ne t'en sers pas
Je rencontre maintenant un problème avec la recopie incrémentée des cellules voila le code exact, mais je n'arrive pas à remplacer le Range(" : "), cette fois encore j'arrive à récupérer les valeurs contenues dans le Range...
Selection.AutoFill Destination:=Range("A22:I22"), Type:=xlFillDefault
Range("A22:I22").Select
Selection.AutoFill Destination:=Range("A22:I24"), Type:=xlFillDefault
Range("A22:I24").Select
Merci d'avance.
Selection.AutoFill Destination:=Range("A22:I22"), Type:=xlFillDefault
Range("A22:I22").Select
Selection.AutoFill Destination:=Range("A22:I24"), Type:=xlFillDefault
Range("A22:I24").Select
Merci d'avance.
8 déc. 2007 à 20:35
cela parait si simple quand c'est toi qui le dis ...
suis admirative
9 déc. 2007 à 00:24
Coucou xkristi, et bonne nuit je suppose