
n = wscal.Range("d" & Rows.Count).End(xlUp).Row |
Private Sub CommandButton1_Click() 'per calcolare tutto
Application.ScreenUpdating = False
k1 = Range("d" & Rows.Count).End(xlUp).Row
For i = k1 To 7 Step -1
If Cells(i, 2) <> "" Then
contcas = 0
conttras = 0
vcas = 0
ncas = 0
pcas = 0
vtras = 0
ntras = 0
ptras = 0
For j = k1 To 7 Step -1
If Cells(i, 2) = Cells(j, 2) And contcas < 25 Then
contcas = contcas + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is > 0
vcas = vcas + 1
Case Is < 0
pcas = pcas + 1
Case Else
ncas = ncas + 1
End Select
End If
If Cells(i, 3) = Cells(j, 3) And conttras < 25 Then
conttras = conttras + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is < 0
vtras = vtras + 1
Case Is > 0
ptras = ptras + 1
Case Else
ntras = ntras + 1
End Select
End If
Next
Cells(i, 6) = 1 / ((vcas + ptras) / 50)
Cells(i, 7) = 1 / ((ncas + ntras) / 50)
Cells(i, 8) = 1 / ((pcas + vtras) / 50)
End If
Next
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click() 'per calcolare ultimo weekend/10 partite
Application.ScreenUpdating = False
k1 = Range("d" & Rows.Count).End(xlUp).Row
For i = k1 To k1 - 9 Step -1
If Cells(i, 2) <> "" Then
contcas = 0
conttras = 0
vcas = 0
ncas = 0
pcas = 0
vtras = 0
ntras = 0
ptras = 0
For j = k1 To 7 Step -1
If contcas >= 25 And conttras >= 25 Then
Exit For
End If
If Cells(i, 2) = Cells(j, 2) And contcas < 25 Then
contcas = contcas + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is > 0
vcas = vcas + 1
Case Is < 0
pcas = pcas + 1
Case Else
ncas = ncas + 1
End Select
End If
If Cells(i, 3) = Cells(j, 3) And conttras < 25 Then
conttras = conttras + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is < 0
vtras = vtras + 1
Case Is > 0
ptras = ptras + 1
Case Else
ntras = ntras + 1
End Select
End If
Next
Cells(i, 6) = 1 / ((vcas + ptras) / 50)
Cells(i, 7) = 1 / ((ncas + ntras) / 50)
Cells(i, 8) = 1 / ((pcas + vtras) / 50)
End If
Next
Application.ScreenUpdating = True
End Sub
|
Private Sub CommandButton1_Click() 'per calcolare tutto
Application.ScreenUpdating = False
k1 = Range("d" & Rows.Count).End(xlUp).Row
k2 = Range("d" & Rows.Count).End(xlUp).Row
For i = k1 To 7 Step -1
If Cells(i, 2) <> "" Then
contcas = 0
conttras = 0
vcas = 0
ncas = 0
pcas = 0
vtras = 0
ntras = 0
ptras = 0
For j = k2 To 7 Step -1
If Cells(i, 2) = Cells(j, 2) And contcas < 25 Then
contcas = contcas + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is > 0
vcas = vcas + 1
Case Is < 0
pcas = pcas + 1
Case Else
ncas = ncas + 1
End Select
End If
If Cells(i, 3) = Cells(j, 3) And conttras < 25 Then
conttras = conttras + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is < 0
vtras = vtras + 1
Case Is > 0
ptras = ptras + 1
Case Else
ntras = ntras + 1
End Select
End If
Next
Cells(i, 6) = 1 / ((vcas + ptras) / 50)
Cells(i, 7) = 1 / ((ncas + ntras) / 50)
Cells(i, 8) = 1 / ((pcas + vtras) / 50)
End If
Next
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click() 'per calcolare ultimo weekend/10 partite
Application.ScreenUpdating = False
k1 = Range("b" & Rows.Count).End(xlUp).Row
k2 = Range("d" & Rows.Count).End(xlUp).Row
For i = k1 To k1 - 9 Step -1
If Cells(i, 2) <> "" Then
contcas = 0
conttras = 0
vcas = 0
ncas = 0
pcas = 0
vtras = 0
ntras = 0
ptras = 0
For j = k2 To 7 Step -1
If contcas >= 25 And conttras >= 25 Then
Exit For
End If
If Cells(i, 2) = Cells(j, 2) And contcas < 25 Then
contcas = contcas + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is > 0
vcas = vcas + 1
Case Is < 0
pcas = pcas + 1
Case Else
ncas = ncas + 1
End Select
End If
If Cells(i, 3) = Cells(j, 3) And conttras < 25 Then
conttras = conttras + 1
Select Case (Cells(j, 4) - Cells(j, 5))
Case Is < 0
vtras = vtras + 1
Case Is > 0
ptras = ptras + 1
Case Else
ntras = ntras + 1
End Select
End If
Next
Cells(i, 6) = 1 / ((vcas + ptras) / 50)
Cells(i, 7) = 1 / ((ncas + ntras) / 50)
Cells(i, 8) = 1 / ((pcas + vtras) / 50)
End If
Next
Application.ScreenUpdating = True
End Sub
|
Option Explicit
Sub QuoteMie_Textomb()
' Il Procedimento adottato:
' Individuo il numero delle squadre presenti nel foglio utilizzando una collection
' Così facendo mi dimensiono le due matrici necessarie a contenerle.
' Costruisco una matrice dove raggruppo i risultati ottenuti delle squadre di casa
' Ed un'altra in cui raggruppo i risultati delle squadre fuori casa
' Quindi, calcolo le QUOTE MIE riferite al gruppo delle squadre che dovranno disputare il match successivo
' Alla fine sparo il contenuto delle matrici nel foglio 25 Partite sere A aggiornando i risultati.
Dim collNS As New Collection, nS As Integer, RisDC(), RisFC(), nrDC As Integer, nrFC As Integer 'Le matrici dei risultati
Dim Lr As Long, i As Long, SquadraDC As String, SquadraFC As String
Dim sh As Worksheet, nR As Byte, sQ As String, Ris
Dim SDCasa As String, SFCasa As String, nVdc As Byte, nNdc As Byte, nPdc As Byte, nVfc As Byte, nNfc As Byte, nPfc As Byte
Set sh = Worksheets(Foglio2.Name)
Lr = sh.Cells(Rows.Count, 5).End(xlUp).Row
On Error Resume Next
For i = 7 To Lr
sQ = Trim(sh.Range("c" & i).Value)
If sQ <> "" Then collNS.Add sQ, Key:=sQ
Next
On Error GoTo 0
'Dimensiono le matrici dei risultati e gli passo i nomi delle squadre
ReDim Preserve RisDC(1 To collNS.Count, 1 To 5)
ReDim Preserve RisFC(1 To collNS.Count, 1 To 5)
For nS = 1 To collNS.Count
RisDC(nS, 2) = collNS(nS)
RisFC(nS, 2) = collNS(nS)
Next
' Le 5 colonne delle matrici rappresentano rispettivamente
'1:Numero degli ultimi incontri presi in esame (contatore)
'2:Nome della Squadra
'3:N. Incontri Vinti
'4:N. Incontri Pareggiati
'5:N. Incontri Persi
'Popolo la matrice dei risultati ottenuti dentro casa RisDC()
For i = Lr To 7 Step -1
SquadraDC = Trim(sh.Range("c" & i)) 'Squadra dentro casa
SquadraFC = Trim(sh.Range("d" & i)) 'Squadra fuori casa
If sh.Range("e" & i) > sh.Range("f" & i) Then
Ris = Array(1, 0, 0)
ElseIf sh.Range("e" & i) = sh.Range("f" & i) Then
Ris = Array(0, 1, 0)
ElseIf sh.Range("e" & i) < sh.Range("f" & i) Then
Ris = Array(0, 0, 1)
End If
nrDC = 0
nrFC = 0
If SquadraDC <> "" And SquadraFC <> "" Then
Do
nR = nR + 1
If RisDC(nR, 2) = SquadraDC Then nrDC = nR
If RisFC(nR, 2) = SquadraFC Then nrFC = nR
Loop Until nrDC <> 0 And nrFC <> 0
nR = 0
If RisDC(nrDC, 1) < 25 Then
RisDC(nrDC, 1) = RisDC(nrDC, 1) + 1
RisDC(nrDC, 3) = RisDC(nrDC, 3) + Ris(0)
RisDC(nrDC, 4) = RisDC(nrDC, 4) + Ris(1)
RisDC(nrDC, 5) = RisDC(nrDC, 5) + Ris(2)
End If
If RisFC(nrFC, 1) < 25 Then
RisFC(nrFC, 1) = RisFC(nrFC, 1) + 1
RisFC(nrFC, 3) = RisFC(nrFC, 3) + Ris(2)
RisFC(nrFC, 4) = RisFC(nrFC, 4) + Ris(1)
RisFC(nrFC, 5) = RisFC(nrFC, 5) + Ris(0)
End If
End If
'Debug.Print SquadraDC & "-" & SquadraFC & ": " & sh.Range("d" & i) & " - " & sh.Range("e" & i)
Next
' Calcolo le QUOTE MIE
Lr = sh.Cells(Rows.Count, 5).End(xlUp).Row + 1 'Ultimo gruppo dei risultati registrati
For i = Lr To (Lr + 9) 'Gruppo delle squadre che dovranno giocare nel prossimo turno
SDCasa = Trim(sh.Range("c" & i)) 'Squadra di casa
SFCasa = Trim(sh.Range("d" & i)) 'Squadra fuori casa
If SDCasa = "" Or SFCasa = "" Then MsgBox "Impossibile procedere con il calcolo", vbCritical: Exit Sub
nrDC = 0
nrFC = 0
Do
nR = nR + 1
If RisDC(nR, 2) = SDCasa Then nrDC = nR
If RisFC(nR, 2) = SFCasa Then nrFC = nR
Loop Until nrDC <> 0 And nrFC <> 0
nR = 0
nVdc = RisDC(nrDC, 3) 'N. Partite Vinte in Casa
nNdc = RisDC(nrDC, 4) 'N. Partite Pareggiate in Casa
nPdc = RisDC(nrDC, 5) 'N. Partite Perse in Casaa
nVfc = RisFC(nrFC, 3) 'N. Partite Vinte Fuori Casa
nNfc = RisFC(nrFC, 4) 'N. Partite Pareggiate Fuori Casa
nPfc = RisFC(nrFC, 5) 'N. Partite Perse Fuori Casa
'Adesso i Risultati delle Quote mie
sh.Range("G" & i).Value = 1 / ((nVdc + nPfc) / 50)
sh.Range("H" & i).Value = 1 / ((nNdc + nNfc) / 50)
sh.Range("I" & i).Value = 1 / ((nPdc + nVfc) / 50)
Next
'Riporto per completezza anche i risultati ottenuti delle ultime 25 Partite per ogni squadra
With Foglio1
.Range("A4:E" & UBound(RisDC) + 3).Value = RisDC
.Range("A4").Sort , key1:=.Range("B4"), Order1:=xlAscending, Header:=xlNo
.Range("G4:K" & UBound(RisFC) + 3).Value = RisFC
.Range("G4").Sort , key1:=Foglio1.Range("H4"), Order1:=xlAscending, Header:=xlNo
End With
MsgBox "Calcolo Completato!", vbInformation
Set sh = Nothing
End Sub
|
