Gentilissimo Anthony ... grazie per la tua preziosa disponibilità .. Vediamo se con un supplemento di spiegazioni si riesce a capire dove mi trovo...
Ricominciando da zero, l'obiettivo è di riempire le 18 righe, con numeri da 1 al 90, sul tabellone(P4:T21) e, per fare questo uso un’unica macro che io ho suddiviso in tre blocchi per maggiore descrizione eccola...
'PRIMA PARTE CERCA I NUMERI E LI SCRIVE A PARTIRE DA X2(va bene e funge a meraviglia)
- Codice: Seleziona tutto
Sub Cerca_Su_5C_4_Numeri()
Dim wArr, oArr(), lastC, I As Long, J As Long
Dim lFor As Integer, kO As Long, kV As Long, kJ As Long
Dim lDue As Integer, matCnt As Integer
lastC = Cells(Rows.Count, 9).End(xlUp).Row
wArr = Range("I3:M" & lastC).Value
lFor = Range("P3").Value
J = Application.WorksheetFunction.CountIf(Range("I3:M" & lastC), lFor)
ReDim oArr(1 To J, 1 To 5)
For I = LBound(wArr) To UBound(wArr)
If lDue > 0 Then matCnt = 0 Else matCnt = 1
For J = 1 To 5
If wArr(I, J) = lFor Or wArr(I, J) = lDue Then
matCnt = matCnt + 1
End If
If matCnt = 2 Then
kO = kO + 1: kJ = 0
For kV = 1 To 5
If wArr(I, kV) <> lFor And wArr(I, kV) <> lDue Then
kJ = kJ + 1
oArr(kO, kJ) = wArr(I, kV)
End If
Next kV
Exit For
End If
Next J
Next I
Range("X:AA").ClearContents
Range("X2").Resize(UBound(oArr, 1), 4) = oArr
Questa prima parte è una macro di un precedente aiuto è funzionante ed è anche veloce va a cercare il numero scritto in P3 nelle righe dell’archivio e trovato il numero prende i 4 numeri associati(sulla stessa riga) e li scrive tutti a partire da X2:AA(end)...
'SECONDA PARTE METTE IN ORDINE DECRESCENTE LE COLONNE X2:AA(end) va bene e funge una meraviglia
- Codice: Seleziona tutto
Range("X2:AA10000").Select
ActiveWorkbook.Worksheets("Sviluppo").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sviluppo").Sort.SortFields.Add Key:=Range( _
"AA2:AA10000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sviluppo").Sort
.SetRange Range("X2:AA10000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.Panes(1).Activate
Range("AC2").Select
Questa è una macro registrata con il registratore di macro e mette il range X2:AA(end) in ordine decrescente... anche questa non è da velocizzare
'TERZA PARTE CONFRONTO E SCRITTURA DEI NUMERI SUL TABELLONE(P4:T21) è la parte da modificare per velocizzarla il più possibile.
- Codice: Seleziona tutto
Dim area As Range
10
If Range("AA2").Value = "" Then Exit Sub’se non ci sono dati in AA2 esci dalla macro
Dim X As Object 'Integer
Set area = Range("P4:T21")
For Each X In area
If X.Value = Range("X2").Value _
Or X.Value = Range("Y2").Value _
Or X.Value = Range("Z2").Value _
Or X.Value = Range("AA2").Value Then GoTo 20
Next
Range("X2:AA2").Copy
'Posizione dove incollare i dati
Dim iRow As Integer
iRow = 4 'riga
While Cells(iRow, 16).Value <> "" '16 la P
iRow = iRow + 1
Wend
Cells(iRow, 16).Select 'wae impila in P4
'ActiveSheet.Paste
'wae solo valori altrimenti cancella la FC
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = True
GoTo 30
20
Range("X2:AA2").Select
Selection.Delete Shift:=xlUp
Range("V2").Select
GoTo 10
30
Range("V2").Select
Set area = Nothing
End Sub
Questa è la parte interessata che è molto lenta ed è da velocizzare il più possibile ... questa macro “casareccia” funziona e porta a termine il suo lavoro ma è lenta quindi questa macro ha la funzione di confrontare i 4 numeri per volta X2:AA2 con tutti quelli del tabellone(P4:T21)
a) se c’è anche un solo numero presente sul tabellone “scarta” tutta la quartina tira su le 4 celle e continua a confrontare un’altra fintanto che ci sono dati in AA2 ... se non ci sono dati in AA2 perché finiscono lascia il buco che verrà riempito con il prossimo confronto ... se rimane un buco in fondo(la 17 o la 18à riga) lo riempie un’altra macro di un tuo precedente aiuto di nome [Sub Filler(ByVal tArea As String)].
b) se tutti i 4 numeri non sono presenti sul tabellone(P4:T21) scrive i 4 numeri a patire da P4...
Spero di aver dato ulteriori spiegazioni al completamento dell’aiuto ... non finirò mai di ringraziarti per il tuo tempo che mi dedichi ... Cordialmente ikwae