Grande! Funziona benissimo. Ho solo 2 cose da chiederti
Ma è possibile separare i vari filtri nelle relative colonne? Ad esempio tabella A1:E100, sarebbe bello poter visualizzare i filtri attivi in A105, B105, C105, D105 e E105 (dove non c'è filtro "")
Ovviamente mi interesserebbe anche limitare il campo della tabella? (se riconosce dunque solo il campo della tabella.
Ecco un esempio in cui ho filtrato solo per colonna A e colonna C:
| Dato1 |
Dato2 |
Dato3 |
Dato4 |
| a5 |
b15 |
c29 |
d37 |
| a3 |
b11 |
c25 |
d34 |
| a10 |
b11 |
c25 |
d35 |
| a5 |
b17 |
c26 |
d35 |
| a3 |
b15 |
c22 |
d33 |
|
|
|
|
|
|
|
|
| Filtri ColA |
Filtri ColB |
Filtri ColC |
Filtri ColD |
| a10, <br><br>a3, <br><br>a5, <br><br>a6 |
|
c22, <br><br>c25, <br><br>c26, <br><br>c29 |
|
Grazie e scuami la pignoleria
Restando nel mio esempio, prova a sostituire il codice con questo:
Public Sub m()
Dim sh As Worksheet
Dim rng As Range
Dim rCol As Range
Dim c As Range
Dim lURiga As Long
Dim col As Collection
Dim v As Variant
Dim s As String
Dim lCol As Long
Dim lriga As Long
Dim sCriteria As String
Dim lCont As Long
Dim lRifRiga As Long
Set sh = ThisWorkbook.Worksheets("Foglio1")
lCont = 101
With sh
If .AutoFilterMode Then
Set rng = .AutoFilter.Range
lURiga = rng.SpecialCells(xlCellTypeLastCell).Row
For lCol = 1 To rng.Columns.Count
lRifRiga = .Cells(.Rows.Count, lCol).End(xlDown).Row
.Range(Cells(101, lCol), Cells(lRifRiga, lCol)).Clear
Next
If rng.Rows.Count > rng.SpecialCells(xlCellTypeVisible).Rows.Count Then
On Error Resume Next
For lCol = 1 To rng.Columns.Count
sCriteria = .AutoFilter.Filters(lCol).Criteria1
If Err.Number = 1004 Then
Err.Number = 0
Else
Set rCol = Range(rng(1, lCol), rng(lURiga, lCol)).SpecialCells(xlCellTypeVisible)
Set col = New Collection
For Each c In rCol
col.Add CStr(c.Value), CStr(c.Value)
Next
For Each v In col
's = s & v & ","
.Cells(lCont, lCol).Value = v
lCont = lCont + 1
Next
Set col = Nothing
lCont = 101
End If
Next
'.Range("F1").Value = Left(s, Len(s) - 1)
Else
'.Range("F1").Value = "Nessun criterio"
End If
End If
End With
Set c = Nothing
Set rCol = Nothing
Set col = Nothing
Set rng = Nothing
Set sh = Nothing
End Sub
NOTA. Metto i criteri da riga 101 per ciascuna colonna. Modifica come preferisci.