Te anexo la macro para userform
Dim h1, h2, h3, h4
'
Private Sub CommandButton1_Click()
'Por.Dante Amor
If ComboBox1.Value <> "" Then
If ComboBox2.Value = "" Or ComboBox2.ListIndex = -1 Then
MsgBox "Selecciona un año", vbExclamation
ComboBox2.SetFocus
Exit Sub
End If
Else
If ComboBox2.Value <> "" Then
MsgBox "Selecciona un mes", vbExclamation
ComboBox1.SetFocus
Exit Sub
End If
End If
'
j = 2
For i = 2 To h1.Range("D" & Rows.Count).End(xlUp).Row
'busca exclusiones
compra = h1.Cells(i, "D")
proced = h1.Cells(i, "H")
estado = h1.Cells(i, "O")
fecha = h1.Cells(i, "AF")
'
If ComboBox1.Value <> "" Then
mes = ComboBox1.ListIndex + 1
año = Val(ComboBox2)
Else
mes = Month(fecha)
año = Year(fecha)
End If
'
If Month(fecha) = mes And Year(fecha) = año Then
Set b = h2.Columns("A").Find(compra, lookat:=xlWhole)
If b Is Nothing Then
Set b = h2.Columns("C").Find(proced, lookat:=xlWhole)
If b Is Nothing Then
Set b = h2.Columns("E").Find(estado, lookat:=xlWhole)
If b Is Nothing Then
'copiar
h1.Rows(i).Copy h3.Rows(j)
j = j + 1
End If
End If
End If
End If
Next
Application.ScreenUpdating = True
MsgBox "Filtro terminado", vbInformation
Unload Me
End Sub
'
Private Sub UserForm_Activate()
'Por.Dante Amor
'
Set h1 = Sheets("Datos originales")
Set h2 = Sheets("exclusiones")
Set h3 = Sheets("Orden de inicio")
Set h4 = Sheets("temp")
'
H3.Rows("2:" & Rows. Count). Clear
H4. Cells. Clear
Application.ScreenUpdating = False
'copia fechas
H1. Columns("AF"). Copy h4. Range("A1")
u4 = h4.Range("A" & Rows.Count).End(xlUp).Row
h4.Range("B1") = h4.Range("A1")
With h4.Range("B2:B" & u4)
.FormulaR1C1 = "=IF(RC[-1]="""","""",YEAR(RC[-1]))"
.Value = .Value
End With
h4.Range("B1:B" & u4).RemoveDuplicates Columns:=1, Header:=xlYes
'
'carga años
For i = 2 To h4.Range("B" & Rows.Count).End(xlUp).Row
If h4.Cells(i, "B") <> "" Then
ComboBox2.AddItem h4.Cells(i, "B")
End If
Next
'
'carga meses
For i = 1 To 12
ComboBox1.AddItem WorksheetFunction.Proper(Format(DateSerial(Year(Date), i, 1), "mmmm"))
Next
End Subsal u dos