Ho creato una macro abbinata ad un pulsante, in cui ho dei riferimenti precisi.
Il mio problema è quello di dover inserire il pulsante ogni 40 righe, e deve in quel contesto,
aggiornare i riferimenti alla riga in cui si trova, per cui avrò Esempio 10 pulsanti,
abbinati ad una macro che è identica, cambiano solo i riferimenti.
Volevo sapere se esiste una forma per evitare di cambiare in tutti i pulsanti i vari
riferimenti.
Sono nuovo al vba e sicuramente farà pena la macro che includo, ma non sò fare meglio.
Copiando il Range da A1 a BC35, poi mi posiziono alla riga 40,80,120,160e 200, e copio
tutto, compreso il pulsante, ma dovrei cambiare tutti i riferimenti.
- Codice: Seleziona tutto
Sub RisultatiGioco()
For tempo = 1 To 1000000
If tempo = 30000 Then
Call Ammonizione01
End If
If tempo = 50000 Then
Call Ammonizione02
End If
If tempo = 70000 Then
Call Ammonizione02
Call Ammonizione01
End If
Next
Call Infortuni01
Call Infortuni02
For colonna = 9 To 55 Step 46
riga = 2
Randomize
Num = Int(Rnd() * 4)
Cells(riga, colonna) = Num
Next
Call Reti01
Call Reti02
End Sub
Sub Ammonizione01()
col01 = 6
Randomize
Caus01 = Int(Rnd() * 2)
For Prob01 = 0 To Caus01
Num01 = Int(Rnd() * 15)
If Cells(Num01 + 5, 7) = 1 Then
Num01 = 0
End If
If Cells(Num01 + 5, col01) = 0 Then
Cells(Num01 + 5, col01) = 1
Else
Cells(Num01 + 5, col01) = 1
Cells(Num01 + 5, col01) = 2
End If
If Cells(Num01 + 5, col01) = 2 Then
Cells(Num01 + 5, col01 + 1) = 1
End If
If Cells(Num01 + 5, col01 + 1) = 1 Then
Cells(Num01 + 5, col01) = 0
End If
Next
End Sub
Sub Ammonizione02()
col02 = 52
Randomize
Caus02 = Int(Rnd() * 2)
For Prob02 = 0 To Caus02
Num02 = Int(Rnd() * 15)
If Cells(Num02 + 5, 53) = 1 Then
Num02 = 0
End If
If Cells(Num02 + 5, col02) = 0 Then
Cells(Num02 + 5, col02) = 1
Else
Cells(Num02 + 5, col02) = 1
Cells(Num02 + 5, col02) = 2
End If
If Cells(Num02 + 5, col02) = 2 Then
Cells(Num02 + 5, col02 + 1) = 1
End If
If Cells(Num02 + 5, col02 + 1) = 1 Then
Cells(Num02 + 5, col02) = 0
End If
Next
End Sub
Sub Infortuni01()
col01 = 8
Randomize
Num01 = Int(Rnd() * 15)
If Cells(Num01 + 5, 7) = 1 Then
Num01 = 0
End If
If Cells(Num01 + 5, col01) = 0 Then
Cells(Num01 + 5, col01) = 1
End If
End Sub
Sub Infortuni02()
col02 = 54
Randomize
Num02 = Int(Rnd() * 15)
If Cells(Num02 + 5, 54) = 1 Then
Num02 = 0
End If
If Cells(Num02 + 5, col02) = 0 Then
Cells(Num02 + 5, col02) = 1
End If
End Sub
Sub Reti01()
Goal01 = Cells(2, 9).Value
col01 = 9
For ReteA = 0 To Goal01 - 1
Randomize
Num01 = Int(Rnd() * 10)
Ret01 = Cells(Num01 + 6, col01).Value
If Cells(Num01 + 6, col01) = 0 Then
Cells(Num01 + 6, col01) = 1
Else
Cells(Num01 + 6, col01) = Ret01 + 1
End If
Next
End Sub
Sub Reti02()
Goal02 = Cells(2, 55).Value
col02 = 55
For ReteB = 0 To Goal02 - 1
Randomize
Num02 = Int(Rnd() * 10)
Ret02 = Cells(Num02 + 6, col02).Value
If Cells(Num02 + 6, col02) = 0 Then
Cells(Num02 + 6, col02) = 1
Else
Cells(Num02 + 6, col02) = Ret02 + 1
End If
Next
End Sub
Ringrazio chi può aiutarmi e consigliarmi.
Francesco