Moderatori: Anthony47, Flash30005
Sub random31()
'
'On Error GoTo Errore
'
''LR = Cells(Rows.Count, "B").End(xlUp).Row
'
''For r = 1 To LR
'
''If Cells(r, 2) = Cells(r, 6) Or Cells(r, 3) = Cells(r, 7) Then
'
ripetI1:
CC2 = 0
first = 1: last = 30
ReDim arr(first To last, 1 To 1)
For i = first To last
arr(i, 1) = i
Next
For i = last To first Step -1
reJ1:
j = Rnd * (last - first + 1) + first
If j > last Then j = last
temp = arr(i, 1)
If Cells(arr(i, 1), "B") <> Cells(arr(j, 1), "F") And Cells(arr(i, 1), "C") <> Cells(arr(j, 1), "G") Then
arr(i, 1) = arr(j, 1)
arr(j, 1) = temp
Else
DoEvents
GoTo reJ1
End If
Next
Worksheets("Foglio1").Range("K1:K" & (last - first + 1)) = arr
ripetI2:
Cc3 = 0
first = 1: last = 30
ReDim arr(first To last, 1 To 1)
For i = first To last
arr(i, 1) = i
Next
For i = last To first Step -1
reJ2:
j = Rnd * (last - first + 1) + first
If j > last Then j = last
temp = arr(i, 1)
If Cells(arr(i, 1), "B") <> Cells(arr(j, 1), "F") And Cells(arr(i, 1), "C") <> Cells(arr(j, 1), "G") Then
arr(i, 1) = arr(j, 1)
arr(j, 1) = temp
Else
DoEvents
GoTo reJ2
End If
Next
Worksheets("Foglio1").Range("L1:L" & (last - first + 1)) = arr
For i = 1 To 30
DoEvents
If Cells(i, 12) = Cells(i, 11) Then
CC2 = CC2 + 1
If CC2 > 10 Then
Debug.Print "Loop 2>1"
GoTo ripetI1
Else
Debug.Print "Loop 2"
GoTo ripetI2
End If
End If
Next
ripeti3:
DoEvents
first = 1: last = 30
ReDim arr(first To last, 1 To 1)
For i = first To last
arr(i, 1) = i
Next
For i = last To first Step -1
rej3:
j = Rnd * (last - first + 1) + first
If j > last Then j = last
temp = arr(i, 1)
If Cells(arr(i, 1), "B") <> Cells(arr(j, 1), "F") And Cells(arr(i, 1), "C") <> Cells(arr(j, 1), "G") Then
arr(i, 1) = arr(j, 1)
arr(j, 1) = temp
Else
DoEvents
GoTo rej3
End If
Next
Worksheets("Foglio1").Range("M1:M" & (last - first + 1)) = arr
For i = 1 To 30
DoEvents
If Cells(i, 13) = Cells(i, 11) Or Cells(i, 13) = Cells(i, 12) Then
Cc3 = Cc3 + 1
If Cc3 > 10 Then
Debug.Print "Loop 3>2"
GoTo ripetI2
Else
Debug.Print "Loop 3"
GoTo ripeti3
End If
End If
Next
For j = 1 To 30
For k = 1 To 3
Cells(k + (Cells(j, 10 + k) + 0) * 3, 5) = Cells(j, 10)
Next k
Next j
'
''End If
''Next r
'
'Errore: MsgBox "Nomi non compatibili con la rotazione", vbInformation
'
'Exit Sub
'
End Sub
Sub RivangaXX()
Dim f2Arr, F1St As String, Cas As Long, R3Pos As Range, RCPos As Range
Dim LB0 As Long, UB0 As Long, cItm As Long, cCnt As Long, clErr As Boolean, gErr As Boolean
Dim I As Long, J As Long, oCC As Long, oCC1 As Long, myTim As Single
'
Sheets("Foglio1").Select
f2Arr = Range(Sheets("Foglio2").Range("A2"), Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp)).Value
aaa = UBound(f2Arr)
LB0 = LBound(f2Arr)
UB0 = UBound(f2Arr)
cItm = UB0 - LB0 + 1
F1St = "A4"
Set R3Pos = Range(F1St).Resize(cItm * 3, 1)
'
reAll:
For I = 0 To 2
reI:
f2Arr = Range(Sheets("Foglio2").Range("A2"), Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp)).Value
myTim = Timer
Range(F1St).Range("E" & (I * cItm + 1)).Resize(cItm * (3 - I), 1).ClearContents
cCnt = 0
For J = 1 To cItm
Set RCPos = Range(F1St).Range("A" & (I * cItm + 1)).Resize(cItm, 1)
reJ:
DoEvents
Cas = Int(Rnd() * UB0) + LB0
If f2Arr(Cas, 1) = "" Then GoTo reJ
Range(F1St).Range("E" & (I * cItm + J - 0)) = f2Arr(Cas, 1)
oCC = Evaluate("sum(--(" & RCPos.Range("E1:E" & cItm).Address & "=""" & f2Arr(Cas, 1) & """))")
oCC1 = Evaluate("sum(--((" & R3Pos.Offset(0, 3).Address & "&" & R3Pos.Offset(0, 4).Address & ")=(""" & Range(F1St).Range("D" & (I * cItm + J)).Value & f2Arr(Cas, 1) & """)))")
If Range(F1St).Range("B" & (I * cItm + J - 0)) = Range(F1St).Range("F" & (I * cItm + J - 0)) Then clErr = True Else clErr = False
If Range(F1St).Range("C" & (I * cItm + J - 0)) = Range(F1St).Range("G" & (I * cItm + J - 0)) Then gErr = True Else gErr = False
If (oCC + oCC1) > 2 Or clErr Or gErr Then
DoEvents
If (Timer - myTim) > 15 Or Timer < myTim Then GoTo reAll
cCnt = cCnt + 1
If cCnt > 30 Then
If I > 0 Then
Debug.Print "Loop <1", I
I = I - 1
GoTo reI
Else
Debug.Print "Loop 0>0", I
GoTo reI
End If
Else
Debug.Print "Loop =", I
GoTo reJ
End If
Else
cCnt = 0
End If
'' If [P1] > (I + 1) Then Stop
f2Arr(Cas, 1) = ""
Next J
Next I
MsgBox ("Completato...")
End Sub
cItm = UB0 - LB0 + 1
F1St = "A4" '<<< L'inizio della prima tabella
postaZ = 3 '<<<2 N° di "postazioni"
'
Set R3Pos = Range(F1St).Resize(cItm * postaZ, 1)
reAll:
For I = 0 To (postaZ - 1)
reI:
Range(F1St).Range("E" & (I * cItm + 1)).Resize(cItm * (10 - I), 1).ClearContents
Torna a Applicazioni Office Windows
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 5 |
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 7 |
[EXCEL] controllo corrispondenza tra valori con un vincolo Autore: sbs |
Forum: Applicazioni Office Windows Risposte: 9 |
Visitano il forum: Nessuno e 11 ospiti