Ciao Federico,
Ciao Norman! Grazie per la tua risposta. Qui ho caricato il file d'esempio
https://1drv.ms/x/s!ApJytEL3u81NgbxV38DGSmGHT3cH8g?e=ubpQd6
il foglio di partenza è quello chiamato "in corso". Selezionando il nome della persona, la riga dovrebbe essere copiata nei fogli corrispondenti.
- Alt+F11 per aprire l'editor di VBA
- Alt+IM per inserire un nuovo modulo di codice
- Nel nuovo modulo vuoto, incolla il seguente codice:
'========>>
Option Explicit
'--------->>
Public Function LastRow(Sh As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1)
If Rng Is Nothing Then
Set Rng = Sh.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
End Function
'--------->>
Public Function SheetExists(sSheetName As String, _
Optional ByVal WB As Workbook) As Boolean
On Error Resume Next
If WB Is Nothing Then
Set WB = ThisWorkbook
End If
SheetExists = CBool(Len(WB.Sheets(sSheetName).Name))
On Error GoTo 0
End Function
'<<=========
- Ctrl+R per accedere alla finestra Project Explorer ('Gestione progetti')
- Fai doppio clic sul modulo ThisWorkbook (Questa_cartella_di_Lavoro) del file e incolla il seguente codice:
'========>>
Option Explicit
Option Compare Text
'-------->>
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim srcSH As Worksheet, destSH As Worksheet
Dim srcRng As Range, destRng As Range
Dim arrIn As Variant, arrOut() As Variant
Dim sNome As String
Dim i As Long, j As Long
Dim iCol As Long, iCtr As Long
Dim LRow As Long
Const sFoglio_Sorgente As String = "In corso"
Const sColonne As String = "A:I"
Const sPrefisso As String = "In corso "
If Sh.Name = Trim(sPrefisso) Then
Exit Sub
End If
Set srcSH = ThisWorkbook.Sheets(sFoglio_Sorgente)
LRow = LastRow(srcSH)
iCol = Sh.Range(sColonne).Columns.Count
sNome = Replace(Sh.Name, sPrefisso, vbNullString)
Set srcRng = srcSH.Range(sColonne).Resize(LRow - 2).Offset(2)
arrIn = srcRng.Value
For i = 1 To UBound(arrIn)
If arrIn(i, 5) = sNome Then
iCtr = iCtr + 1
ReDim Preserve arrOut(1 To iCol, 1 To iCtr)
For j = 1 To iCol
arrOut(j, iCtr) = arrIn(i, j)
Next j
End If
Next i
Sh.UsedRange.Offset(2).ClearContents
If CBool(iCtr) Then
Sh.Range("A3").Resize(iCtr, icol).Value = Application.Transpose(arrOut)
End If
End Sub
'<<========
- Salva il file con l'estensione xlsm
Potresti scaricare il mio file di prova Federico20200612.xlsm
'===
Regards,
Norman
