Pb avec formule
Bonjour à Tous,
J'essaie depuis quelques jours de mettre en forme une formule que j'aurais besoin de répéter sur plusieurs lignes.
Tout d'abord, je vais vous expliquer le but du fichier, celui-ci a pour but de gérer un tournoi sportif avec un nombre d'équipe pouvant varier.
Sur la feuille "Tirage Groupes", j'inscris le nombre d'équipe dans la colonne A, puis, via une macro, je réalise le tirage au sort et les rencontres sont inscrites dans les colonnes F et H.
Sur la feuille "Ronde N°1", via une macro, je copie les rencontres inscrites sur la feuille "Tirage Groupes" dans les colonnes C à I.
Puis, via une autre macro, je réalise le tableau de classement dans les colonnes K à R.
Et c'est là, que cela se corse.... J'ai bien réussi pour la 1ère partie (equipes inscrites dans colonne C) mais je n'y arrive pas à inscrire de formules pour la 2nde partie car lorsque je change de nombre d'équipes et donc de nombre de rencontres, ma formule n'est plus bonne.
La voici (en tout cas le bout qui me pose problème) :
Range("G4:G" & Range("G64000").End(xlUp).Row).Copy
Range("L64000").End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
' Colonne Matchs joués pour 2nde colonne
Formule = "=IF(R[-40]C[-4]="""",0,1)"
Sheets("Ronde N°1").Range("M65536").End(xlUp).Offset(1, 0).Select
With Selection
.Formula = Formule
.HorizontalAlignment = xlCenter
End With
'Selection.AutoFill Destination:=Range("M4:M" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Set Ws = Sheets("Ronde N°1")
DerLig = Ws.Cells(Ws.Columns(13).Cells.Count, 13).End(xlUp).Row
With Ws
'Je détermine le numéro de la dernière ligne renseignée dans la colonne L
DerLigL = .Range("L" & .Rows.Count).End(xlUp).Row
'Je détermine le numéro de la dernière ligne renseignée dans la colonne M
DerLigM = .Range("M" & .Rows.Count).End(xlUp).Row
'J'effectue la recopie incrémentée dans la colonne M
.Range("M" & DerLigM).AutoFill Destination:=.Range(.Range("M" & DerLigM), .Range("M" & DerLigL))
End With
Dans cette macro :
Sub test()
Dim Ws As Worksheet
Dim DerLig As Long
Range("C4:C" & Range("C64000").End(xlUp).Row).Copy
Range("L64000").End(xlUp)(4).PasteSpecial Paste:=xlPasteValues
' Colonne Matchs joués pour 1ère colonne
Formule = "=IF(RC[-8]="""",0,1)"
Sheets("Ronde N°1").Range("M4").Formula = Formule
Range("M4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("M4:M" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
' Colonne Matchs gagnés pour 1ère colonne
Formule = "=IF(RC[-9]=50,1,0)"
Sheets("Ronde N°1").Range("N4").Formula = Formule
Range("N4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("N4:N" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
' Colonne Matchs perdus pour 1ère colonne
Formule = "=IF(RC[-10]<>50,1,0)"
Sheets("Ronde N°1").Range("O4").Formula = Formule
Range("O4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("O4:O" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
' Colonne Pts pour 1ère colonne
Formule = "=RC[-11]"
Sheets("Ronde N°1").Range("P4").Formula = Formule
Range("P4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("P4:P" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
' Colonne Pts Adv. pour 1ère colonne
Formule = "=RC[-8]"
Sheets("Ronde N°1").Range("Q4").Formula = Formule
Range("Q4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("Q4:Q" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
' Colonne Différence pour 1ère colonne
Formule = "=RC[-13]-RC[-9]"
Sheets("Ronde N°1").Range("R4").Formula = Formule
Range("R4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("R4:R" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Range("G4:G" & Range("G64000").End(xlUp).Row).Copy
Range("L64000").End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
' Colonne Matchs joués pour 2nde colonne
Formule = "=IF(R[-40]C[-4]="""",0,1)"
Sheets("Ronde N°1").Range("M65536").End(xlUp).Offset(1, 0).Select
With Selection
.Formula = Formule
.HorizontalAlignment = xlCenter
End With
'Selection.AutoFill Destination:=Range("M4:M" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Set Ws = Sheets("Ronde N°1")
DerLig = Ws.Cells(Ws.Columns(13).Cells.Count, 13).End(xlUp).Row
With Ws
'Je détermine le numéro de la dernière ligne renseignée dans la colonne L
DerLigL = .Range("L" & .Rows.Count).End(xlUp).Row
'Je détermine le numéro de la dernière ligne renseignée dans la colonne M
DerLigM = .Range("M" & .Rows.Count).End(xlUp).Row
'J'effectue la recopie incrémentée dans la colonne M
.Range("M" & DerLigM).AutoFill Destination:=.Range(.Range("M" & DerLigM), .Range("M" & DerLigL))
End With
Range("K4").Select
ActiveCell.FormulaR1C1 = "1"
Range("K5").Select
ActiveCell.FormulaR1C1 = "2"
Range("K4:K5").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.AutoFill Destination:=Range("K4:K" & Range("L" & Rows.Count).End(xlUp).Row), Type:=xlFillDefault
Range("K3").Select
ActiveCell.FormulaR1C1 = "Classement"
Columns("L:L").ColumnWidth = 10
With Selection
.HorizontalAlignment = xlCenter
End With
Range("L3").Select
ActiveCell.FormulaR1C1 = "Nom Equipe"
Columns("L:L").ColumnWidth = 23
With Selection
.HorizontalAlignment = xlCenter
End With
Range("M3").Select
ActiveCell.FormulaR1C1 = "J"
Columns("M:M").ColumnWidth = 3
With Selection
.HorizontalAlignment = xlCenter
End With
Range("N3").Select
ActiveCell.FormulaR1C1 = "V"
Columns("N:N").ColumnWidth = 3
With Selection
.HorizontalAlignment = xlCenter
End With
Range("O3").Select
ActiveCell.FormulaR1C1 = "D"
Columns("O:O").ColumnWidth = 3
With Selection
.HorizontalAlignment = xlCenter
End With
Range("P3").Select
ActiveCell.FormulaR1C1 = "Pts"
Columns("P:P").ColumnWidth = 7
With Selection
.HorizontalAlignment = xlCenter
End With
Range("Q3").Select
ActiveCell.FormulaR1C1 = "Pts Adv"
Columns("Q:Q").ColumnWidth = 7
With Selection
.HorizontalAlignment = xlCenter
End With
Range("R3").Select
ActiveCell.FormulaR1C1 = "Différence"
Columns("R:R").ColumnWidth = 8
With Selection
.HorizontalAlignment = xlCenter
End With
Range("K2").Select
End Sub
Je mets une copie du fichier, si je n'est pas été assez clair
Et je vous remercie d'avance de l'aide que vous pourrez m'apporter.
Youlig
Bonsoir à Tous,
Personne n'a d'idées pour orienter mes recherches...
Olivier
Bonjour,
J'avance un peu... mais comment écrire une formule sous cette forme :
Formule = "=IF(R[-x/2]C[-4]="""",0,1)"
Avec x = Worksheets("Tirage Groupes").[B2].Value
Le .Formula ne fonctionne pas, j'ai essayé aussi avec le .FormulaR1C1 mais non plus.
Une idée ?
Bonjour,
une proposition de modification de ta procédure test
Sub test()
Dim Ws As Worksheet
Dim DerLig As Long
With Sheets("Ronde N°1")
dlc = .Cells(Rows.Count, "C").End(xlUp).Row
nequipe = dlc - 3
.Range("C4:C" & dlc).Copy
.Range("L4").PasteSpecial Paste:=xlPasteValues
' Colonne Matchs joués pour 1ère colonne
.Range("M4").Formula = "=IF(RC[-8]="""",0,1)"
.Range("N4").Formula = "=IF(RC[-9]=50,1,0)"
.Range("O4").Formula = "=IF(RC[-10]<>50,1,0)"
.Range("P4").Formula = "=RC[-11]"
.Range("Q4").Formula = "=RC[-8]"
.Range("R4").Formula = "=RC[-13]-RC[-9]"
With .Range("M4:R4")
.HorizontalAlignment = xlCenter
.AutoFill Destination:=Range("M4:R" & dlc), Type:=xlFillDefault
End With
plc = dlc + 1
.Range("G4:G" & dlc).Copy
.Range("L" & plc).PasteSpecial Paste:=xlPasteValues
' Colonne Matchs joués pour 2nde colonne
.Range("M" & plc) = "=IF(R[-" & nequipe & "]C[-4]="""",0,1)"
.Range("N" & plc) = "=IF(R[-" & nequipe & "]C[-5]<>50,0,1)"
.Range("O" & plc) = "=IF(R[-" & nequipe & "]C[-6]=50,0,1)"
.Range("P" & plc) = "=R[-" & nequipe & "]C[-7]"
.Range("Q" & plc) = "=R[-" & nequipe & "]C[-12]"
.Range("R" & plc) = "=R[-" & nequipe & "]C[-4]-R[-" & nequipe & "]C[-13]"
With .Range("M" & plc & ":R" & plc)
.HorizontalAlignment = xlCenter
.AutoFill Destination:=Range("M" & plc & ":R" & dlc + nequipe), Type:=xlFillDefault
End With
.Range("K4") = 1
.Range("K5") = 2
With .Range("K4:K5")
.HorizontalAlignment = xlCenter
.AutoFill Destination:=Range("K4:K" & dlc + nequipe), Type:=xlFillDefault
End With
.Range("K3").Select
ActiveCell.FormulaR1C1 = "Classement"
.Columns("L:L").ColumnWidth = 10
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("L3").Select
ActiveCell.FormulaR1C1 = "Nom Equipe"
.Columns("L:L").ColumnWidth = 23
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("M3").Select
ActiveCell.FormulaR1C1 = "J"
.Columns("M:M").ColumnWidth = 3
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("N3").Select
ActiveCell.FormulaR1C1 = "V"
.Columns("N:N").ColumnWidth = 3
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("O3").Select
ActiveCell.FormulaR1C1 = "D"
.Columns("O:O").ColumnWidth = 3
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("P3").Select
ActiveCell.FormulaR1C1 = "Pts"
.Columns("P:P").ColumnWidth = 7
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("Q3").Select
ActiveCell.FormulaR1C1 = "Pts Adv"
.Columns("Q:Q").ColumnWidth = 7
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("R3").Select
ActiveCell.FormulaR1C1 = "Différence"
.Columns("R:R").ColumnWidth = 8
With Selection
.HorizontalAlignment = xlCenter
End With
.Range("K2").Select
End With
End SubBonjour H2SO4,
Un grand Bravo !!! Merci ton code est impeccable.
Je viens de le regarder de plus près et il est facile à comprendre et à suivre. Merci cela va me permettre d'évoluer en VBA pour un autodidacte.
Bonne journée et merci encore.
Youlig