|
||||
|
|
#1 (permalink) |
|
Nuovo della community ![]()
7 Messaggi
![]() |
problema con ciclo For
Ciao a tutti,
visto che sono riuscito in qualche modo a risolvere i primi problemi che vi ho sottoposto in questo forum, mi permetto di porre anche questo. Spero che qualcuno riesca a darmi una mano. Ho una routine che genera numeri casuali (il numero lo decido io sul range a disposizione) e ogni volta che estraggo per esempio 10 numeri, con un'altra routine memorizzo questi dati in un array composto da 10 colonne e x righe (x lo decido io!!). Il mio problema è il seguente: dovendo gestire una mole di dati pari a circa 187000 righe, non appena finisco di riempire il range A1:J65536, voglio passare al range successivo (K1:T65536 e quindi U1:AD65536, per arrivare alla cifra prestabilita!!) per ripetere l'operazione senza interrompere il ciclo di estrazione del mio generatore casuale perchè non voglio che mi si ripetano le combinazioni di dieci numeri. La routine che ho creato, purtroppo genera questo problema: Sub Iterazione() Dim v As Integer Dim w As Integer For v = 1 To 65536 If Cells(v, 1) = "" Then Application.Run "rnd_sem2.xls!pressione_tasti" End If Next v For w = 1 To 65536 If Cells(w, 11) = "" Then Application.Run "rnd_sem2.xls!pressione_tasti": Exit Sub End If Next w End Sub L'istruzione "Application.Run "rnd_sem2.xls!pressione_tasti" esegue contemporaneamente le due routine di cui sopra (estrazione e memorizzazione in colonne). Qualcuno potrebbe darmi una dritta? Grazie. |
|
|
|
|
|
#2 (permalink) |
|
Moderatore Globale ![]() ![]()
6,521 Messaggi
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Perdonami, ma non ho capito il problema...
Per questi lavori, ritengo sia sufficiente impostare 2 cicli nidificati, uno che ti consente di selezionare le colonne, l'altro che ti consente di selezionare le righe. Ovviamente nel ciclo che scorre le colonne puoi impostare uno step sufficiente a reperire il range che ti serve riempire. In pratica, i 2 cicli dovrebbero essere orientativamente così: codice:
n = 12 'Numero di ranges
For c = 1 to (n * 10) step 10
For r = 1 to 65536
Cells(r, c).Value = "quello che ti pare"
'Altro codice da eseguire
Next r
Next c
__________________
![]() ![]() ![]()
|
|
|
|
|
|
#3 (permalink) |
|
Nuovo della community ![]()
7 Messaggi
![]() |
ciclo for nidificato
Ciao,
grazie mille per la dritta. Ovviamente ho subito riadattato il tuo codice per il mio problema ma come succedeva prima continua a farmi lo stesso lavoro cioè invece di spazzolare il primo insieme di 10 colonne e 65536 righe e continuare con il secondo insieme di colonne è come se il ciclo si ripetesse in maniera identica nei due insiemi cioè parte dalla prima riga e memorizza due decine identiche in ciscuna riga successiva. Da questo ho dedotto che evidentemente la routine che precede quella finale cioè quella di memorizzazione delle decine deve essere sbagliata. Allego la stessa per rendere le idee. E' chilometrica e probabilmente poco intelligente ma sono un neofita per cui...non so se qualcuno ha voglia di dirmi dove sbaglio ma ci provo lo stesso: codice:
Sub Pulsante2_Click()
A = Worksheets("generatore").Range("G2").Value
For Each c In Worksheets("Generatore").Range("K22:K10022")
If c.Value = "" Then
c.Value = A
Exit For
End If
Next c
B = Worksheets("generatore").Range("G3").Value
For Each c In Worksheets("Generatore").Range("L22:L10022")
If c.Value = "" Then
c.Value = B
Exit For
End If
Next c
D = Worksheets("generatore").Range("G4").Value
For Each c In Worksheets("Generatore").Range("M22:M10022")
If c.Value = "" Then
c.Value = D
Exit For
End If
Next c
E = Worksheets("generatore").Range("G5").Value
For Each c In Worksheets("Generatore").Range("N22:N10022")
If c.Value = "" Then
c.Value = E
Exit For
End If
Next c
F = Worksheets("generatore").Range("G6").Value
For Each c In Worksheets("Generatore").Range("O22:O10022")
If c.Value = "" Then
c.Value = F
Exit For
End If
Next c
G = Worksheets("generatore").Range("G7").Value
For Each c In Worksheets("Generatore").Range("P22:P10022")
If c.Value = "" Then
c.Value = G
Exit For
End If
Next c
H = Worksheets("generatore").Range("G8").Value
For Each c In Worksheets("Generatore").Range("Q22:Q10022")
If c.Value = "" Then
c.Value = H
Exit For
End If
Next c
I = Worksheets("generatore").Range("G9").Value
For Each c In Worksheets("Generatore").Range("R22:R10022")
If c.Value = "" Then
c.Value = I
Exit For
End If
Next c
J = Worksheets("generatore").Range("G10").Value
For Each c In Worksheets("Generatore").Range("S22:S10022")
If c.Value = "" Then
c.Value = J
Exit For
End If
Next c
K = Worksheets("generatore").Range("G11").Value
For Each c In Worksheets("Generatore").Range("T22:T10022")
If c.Value = "" Then
c.Value = K
Exit For
End If
Next c
L = Worksheets("generatore").Range("G2").Value
For Each c In Worksheets("Generatore").Range("U22:U10022")
If c.Value = "" Then
c.Value = L
Exit For
End If
Next c
M = Worksheets("generatore").Range("G3").Value
For Each c In Worksheets("Generatore").Range("V22:V10022")
If c.Value = "" Then
c.Value = M
Exit For
End If
Next c
n = Worksheets("generatore").Range("G4").Value
For Each c In Worksheets("Generatore").Range("W22:W10022")
If c.Value = "" Then
c.Value = n
Exit For
End If
Next c
O = Worksheets("generatore").Range("G5").Value
For Each c In Worksheets("Generatore").Range("X22:X10022")
If c.Value = "" Then
c.Value = O
Exit For
End If
Next c
P = Worksheets("generatore").Range("G6").Value
For Each c In Worksheets("Generatore").Range("Y22:Y10022")
If c.Value = "" Then
c.Value = P
Exit For
End If
Next c
Q = Worksheets("generatore").Range("G7").Value
For Each c In Worksheets("Generatore").Range("Z22:Z10022")
If c.Value = "" Then
c.Value = Q
Exit For
End If
Next c
r = Worksheets("generatore").Range("G8").Value
For Each c In Worksheets("Generatore").Range("AA22:AA10022")
If c.Value = "" Then
c.Value = r
Exit For
End If
Next c
S = Worksheets("generatore").Range("G9").Value
For Each c In Worksheets("Generatore").Range("AB22:AB10022")
If c.Value = "" Then
c.Value = S
Exit For
End If
Next c
T = Worksheets("generatore").Range("G10").Value
For Each c In Worksheets("Generatore").Range("AC22:AC10022")
If c.Value = "" Then
c.Value = T
Exit For
End If
Next c
U = Worksheets("generatore").Range("G11").Value
For Each c In Worksheets("Generatore").Range("AD22:AD10022")
If c.Value = "" Then
c.Value = U: Exit Sub
Exit For
End If
Next c
End Sub
Ultima modifica di TheTruster : 25-11-2009 a 01:15. |
|
|
|
![]() |
| Strumenti della discussione | |
| Modalità di visualizzazione | |
|
|
Tutti gli orari sono GMT +2. Attualmente sono le 09:50.














Modalità lineare

