Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Nicola,
ho provato la tua routine e come sempre va benissimo.
Ho da chiederti questo:
- è possibile fa uscire un MSGBOX quando non trova il dato da filtrare?
Ciò è necessario poiché i dati sono disposti in 6500 righe e in caso di errore di digitazione del dato da filtrare, desidererei essere avvisato che non esiste.
Prova qualcosa del genere:
'========>>
Option Explicit
'-------->>
Public Sub Tester()
Dim WB As Workbook
Dim srcSH As Worksheet, destSH As Worksheet
Dim srcRng As Range, destRng As Range, foundRng As Range
Dim Res As Variant
Dim i As Long, j As Long
Dim LRow As Long
Dim bFound As Boolean
Const sFoglio_Sorgente As String = "Report" '<<=== Modifica
Const sFoglio_Destinazione As String = "Foglio2" '<<=== Modifica
Const sColonne As String = "A:K" '<<=== Modifica
Const sDestinazione As String = "A1" '<<=== Modifica
Res = Application.InputBox( _
Prompt:="Quale dipendente deve essere copiato?", _
Title:="DIPENDENTE", _
Type:=2)
Set WB = ThisWorkbook
With WB
Set srcSH = .Sheets(sFoglio_Sorgente)
Set destSH = .Sheets(sFoglio_Destinazione)
End With
With srcSH
Set foundRng = .Columns("A:A").Find( _
What:=Res, _
After:=.Range("A1"), _
LookIn:=xlFormulas2, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If .AutoFilterMode Then
.AutoFilterMode = False
End If
If foundRng Is Nothing Then
destSH.Columns(sColonne).ClearContents
Call MsgBox(Prompt:="Il dpendente " & Res & " non e' stato trovato!", _
Buttons:=vbCritical, _
Title:="ERRORE!")
Exit Sub
End If
.Range("A1").AutoFilter _
Field:=1, _
Criteria1:=Res, _
VisibleDropDown:=False
Set srcRng = .AutoFilter.Range.SpecialCells(xlCellTypeVisible)
End With
With destSH
.Range(sColonne).ClearContents
Set destRng = .Range(sDestinazione)
srcRng.Copy Destination:=destRng
LRow = LastRow(destSH, .Columns("A:A"))
If LRow > 1 Then
.Range("G" & LRow + 1).Value = Application.Sum(.Range("G2").Resize(LRow - 1))
.Range("H" & LRow + 1).Value = Application.Sum(.Range("H2").Resize(LRow - 1))
End If
End With
srcSH.AutoFilterMode = False
Call MsgBox(Prompt:="Fatto", Buttons:=vbInformation, Title:="REPORT")
End Sub
'--------->>
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
'<<========
===
Regards,
Norman