| | Post: 482 | Registrato il: 28/05/2011
| Città: MILANO | Età: 43 | Utente Senior | excel 2000/2007 | | OFFLINE | |
|
18/08/2022 15:03 | |
Ciao a tutti.
Questa macro inserendo una X nella collonna Q e poi cliccando nel pulsante "filtra X" mi seleziona le righe
Sub filtraX_1()
'foglio input
Application.ScreenUpdating = False
ActiveSheet.Unprotect "987654"
'If Application.CountA(Range("Q6:Q6000")) = "" Then
If Application.CountIf(Range("Q6:Q100"), "X") < 1 Then
MsgBox "Nessuna X presente!", vbCritical + vbOKOnly, "ATTENZIONE!" 'OK
ActiveSheet.Protect "987654"
Exit Sub
End If
'Range("Q6:Q6000").Select
Application.ScreenUpdating = False
'ActiveSheet.Unprotect "987654"
ActiveSheet.Range("$A$5:$Q$100").AutoFilter Field:=17, Criteria1:="X"
ActiveSheet.Protect "987654"
Application.ScreenUpdating = False
End Sub
E' possibile modificare la macro se vengono selezionate righe vuote nella colonna A appaia avviso:
"hai selezionate delle righe vuote"
e poi esce dalla macro.
Cliccare nel pulsante "togli X" per tornare nella visualizzazione normale.
Spero di essermi spiegato.
Grazie
[Modificato da john_cash 18/08/2022 15:13] ---------------
excel 2007 |
|
| | Post: 1.010 | Registrato il: 24/06/2015
| Città: CATANIA | Età: 80 | Utente Veteran | Excel2019 | | OFFLINE |
|
18/08/2022 16:09 | |
Ciao
Modifica la tua macro così
Sub filtraX_1()
'foglio input
Dim i As Long, n As Integer
Application.ScreenUpdating = False
ActiveSheet.Unprotect "987654"
'--------------------------------------------------------------
For i = 7 To 100
If IsEmpty(Cells(i, 1)) And Not (IsEmpty(Cells(i, 17))) Then
n = n + 1
End If
Next i
If n > 0 Then MsgBox "Hai selezionato righe vuote", vbCritical + vbOKOnly: Exit Sub
'--------------------------------------------------------------
If Application.CountIf(Range("Q6:Q100"), "X") < 1 Then
MsgBox "Nessuna X presente!", vbCritical + vbOKOnly, "ATTENZIONE!" 'OK
ActiveSheet.Protect "987654"
Exit Sub
End If
Application.ScreenUpdating = False
ActiveSheet.Range("$A$5:$Q$100").AutoFilter Field:=17, Criteria1:="X"
ActiveSheet.Protect "987654"
Application.ScreenUpdating = False
End Sub
Il codice entro le lineette è quello che ho aggiunto
Ciao,
Mario |
| | Post: 482 | Registrato il: 28/05/2011
| Città: MILANO | Età: 43 | Utente Senior | excel 2000/2007 | | OFFLINE | |
|
18/08/2022 16:24 | |
Ciao marius grazie, funziona in parte:
Option Explicit
Sub filtraX_1()
'foglio input
Dim i As Long, n As Integer
Application.ScreenUpdating = False
ActiveSheet.Unprotect "987654"
'--------------------------------------------------------------
For i = 7 To 100
If IsEmpty(Cells(i, 1)) And Not (IsEmpty(Cells(i, 17))) Then
n = n + 1
End If
Next i
If n > 0 Then
MsgBox "Hai selezionato righe vuote", vbCritical + vbOKOnly, "ATTENZIONE!":
End If
Exit Sub
'--------------------------------------------------------------
'If Application.CountA(Range("Q6:Q6000")) = "" Then
If Application.CountIf(Range("Q6:Q100"), "X") < 1 Then
MsgBox "Nessuna X presente!", vbCritical + vbOKOnly, "ATTENZIONE!" 'OK
ActiveSheet.Protect "987654"
Exit Sub
End If
'Range("Q6:Q6000").Select
Application.ScreenUpdating = False
'ActiveSheet.Unprotect "987654"
ActiveSheet.Range("$A$5:$Q$100").AutoFilter Field:=17, Criteria1:="X"
ActiveSheet.Protect "987654"
Application.ScreenUpdating = False
End Sub
ora non funziona il filtraggio e se non c'è nessuna X e poi si clicca nel punsante non esce il messaggio "nessuna X presente", prima usciva.
[Modificato da john_cash 18/08/2022 16:25] ---------------
excel 2007 |
| | Post: 483 | Registrato il: 28/05/2011
| Città: MILANO | Età: 43 | Utente Senior | excel 2000/2007 | | OFFLINE | |
|
18/08/2022 17:08 | |
Spostato la parte nuova aggiunta
Sub filtraX_1()
'foglio input
Dim i As Long, n As Integer
'Application.ScreenUpdating = False
ActiveSheet.Unprotect "987654"
'If Application.CountA(Range("Q6:Q6000")) = "" Then
If Application.CountIf(Range("Q6:Q100"), "X") < 1 Then
MsgBox "Nessuna X presente!", vbCritical + vbOKOnly, "ATTENZIONE!" 'OK
ActiveSheet.Protect "987654"
Exit Sub
End If
'Range("Q6:Q6000").Select
Application.ScreenUpdating = False
'ActiveSheet.Unprotect "987654"
ActiveSheet.Range("$A$5:$Q$100").AutoFilter Field:=17, Criteria1:="X"
'--------------------------------------------------------------
For i = 7 To 100
If IsEmpty(Cells(i, 1)) And Not (IsEmpty(Cells(i, 17))) Then
n = n + 1
End If
Next i
If n > 0 Then
MsgBox "Hai selezionato righe vuote", vbCritical + vbOKOnly, "ATTENZIONE!":
Call togli_filtraX_1
End If
Exit Sub
'--------------------------------------------------------------
ActiveSheet.Protect "987654"
Application.ScreenUpdating = False
End Sub
---------------
excel 2007 |
|
|