› Excel e gli applicativi Microsoft Office › Eliminare giorni festivi
-
AutoreArticoli
-
Ciao a tutti, in rete ho trovato questa macro per eliminare sabati e domeniche, mi servirebbe eliminare anche le altre festività
Capodanno, Epifania ecc. 01/01;Capodanno
06/01;Epifania
25/04;Liberazione
01/05;Lavoro
02/06;Republica
15/08;Ferragosto
01/11;Ognissanti
08/12;Immacolata
25/12;Natale
26/12;S.Stefanola macro è
Sub EliminaSabato_Domenica()
Dim i As Long
On Error GoTo fine
For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
If Weekday(Cells(i, "A")) = 1 Or Weekday(Cells(i, "A")) = 7 Then
Cells(i, "A").EntireRow.Delete
End If
fine:
Next i
End SubCome si potrebbe procedere? Grazie
Allegati:
You must be logged in to view attached files.Ciao
Non ho testato ma dovrebbe funzionare.
Crea una tabella con i giorni delle festività e denominala Feste, quindi aggiusta la macro così:
Sub EliminaSabato_Domenica_e_Festivi() Dim i As Long On Error GoTo fine For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1 If Weekday(Cells(i, "A")) = 1 Or Weekday(Cells(i, "A")) = 7 Then Cells(i, "A").EntireRow.Delete Else rg = Application.WorksheetFunction.Match(Cells(i, 1), Feste, 0) If rg > 0 Then Cells(i, "A").EntireRow.Delete End If fine: Next i End SubFai sapere. Ciao,
Mario
L'inconveniente si manifesta in diverse, e oscure, ragioni. Le cause sono difficili da trovare. Può vuol dire che il codice si riferisce a qualcosa che non esiste o non esiste più, spesso basta eseguire il codice passo passo (F8) fino a trovare l'istruzione che blocca il programma. Potrebbe essere per esempio che si fa riferimento a un Range ma poi la cartella di lavoro viene chiusa. O che si tenta di eseguire un comando in una cartella di lavoro che non esiste. Metti Option Explicit in testa al modulo, salva, chiudi Excel, e riavvia.
Hai definito correttamente la tabella "Feste" come ha suggerito Mario?
Ciao, da altro problema variabile non definita.
Allegati:
You must be logged in to view attached files.Ciao
Ti chiedo scusa. Andavo di fretta e sono stato un po' superficiale. Ti allego il file con questa macro
`Option Explicit Sub Elim_Feste_Sab_Dom() Dim ur As Long, i As Long, rg As Long, dd As Integer ur = Cells(Rows.Count, 1).End(xlUp).Row For i = ur To 2 Step -1 On Error Resume Next rg = Application.WorksheetFunction.Match(Cells(i, 1), Range("Feste"), 0) dd = Weekday(Cells(i, 1)) If rg > 0 Or dd = 1 Or dd = 7 Then Rows(i).Delete End If On Error GoTo 0 Next i End Sub`Prova e fai sapere. Ciao,
Mario
Allegati:
You must be logged in to view attached files.Ciao
C'è qualche problema che mi sfugge ma con la macro corretta come appresso "dovrebbe" funzionare
Sub Elim_Feste_Sab_Dom() Dim ur As Long, i As Long, rg As Long, dd As Integer ur = Cells(Rows.Count, 1).End(xlUp).Row For i = ur To 2 Step -1 rg = 0 On Error Resume Next rg = Application.WorksheetFunction.Match(Cells(i, 1), [Feste], 0) On Error GoTo 0 dd = Weekday(Cells(i, 1)) If rg > 0 Or dd = 1 Or dd = 7 Then Rows(i).Delete End If Next i End SubFai sapere. Ciao,
Mario
-
AutoreArticoli
