Excel autofilter incremental

hroerkr11

New Member
Joined
Nov 1, 2018
Messages
1
Hi,

I hope you can help me to solve an issue with this code, I´m using the following code to export the filtered data to a new workbook .
ie. filter information added on sep 15 2018 and create the document then i have to select sep 16 and execute macro to export the info for that day and so for each day.

Im looking for a way to automatically export the information for day 1 to day 31 of each month automatically.

I tried to use a variable here but did not work:
[TABLE="width: 160"]
<tbody>[TR]
[TD="align: right"]17[/TD]
[TD]Sheets("Sheet1").Range("tabla1").AutoFilter Field:=4, Criteria1:=ActiveSheet.Range(****variable here*****).Value[/TD]
[/TR]
</tbody>[/TABLE]



[TABLE="width: 160"]
<colgroup><col width="80" span="2" style="width:60pt"> </colgroup><tbody>[TR]
[TD="width: 80, align: right"]1[/TD]
[TD="class: xl65, width: 80"]Sub Generar_Excel()[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD]Dim Libro1 As String[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD]Dim NuevoLibro As String[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD]Dim MyRange As Range[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD]Dim limpiartabla As ListObject[/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[TD]Dim i as variant[/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]9[/TD]
[TD]'Limpiar filtro[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD]Libro1 = ActiveWorkbook.Name[/TD]
[/TR]
[TR]
[TD="align: right"]11[/TD]
[TD]If Workbooks(Libro1).Worksheets("Sheet1").FilterMode = True Then[/TD]
[/TR]
[TR]
[TD="align: right"]12[/TD]
[TD] Workbooks(Libro1).Worksheets("Sheet1").ShowAllData[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD]End If[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD]'Filtrar informacion[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD]Sheets("Sheet1").Range("tabla1").AutoFilter Field:=2, Criteria1:=ActiveSheet.Range("B1").Value[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD]Sheets("Sheet1").Range("tabla1").AutoFilter Field:=4, Criteria1:=ActiveSheet.Range("B2").Value[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD]Sheets("Sheet1").Range("tabla1").AutoFilter Field:=3, Criteria1:=ActiveSheet.Range("B3").Value[/TD]
[/TR]
[TR]
[TD="align: right"]19[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]20[/TD]
[TD]'Seleccionar valores visibles de tabla[/TD]
[/TR]
[TR]
[TD="align: right"]21[/TD]
[TD]Set MyRange = Sheets("Sheet1").Range("tabla1[#All]").SpecialCells(xlCellTypeVisible)[/TD]
[/TR]
[TR]
[TD="align: right"]22[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]23[/TD]
[TD]'Creación de un nuevo documento[/TD]
[/TR]
[TR]
[TD="align: right"]24[/TD]
[TD]Workbooks.Add[/TD]
[/TR]
[TR]
[TD="align: right"]25[/TD]
[TD]NuevoLibro = ActiveWorkbook.Name[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]27[/TD]
[TD]'Copiar el rango del libro a exportar[/TD]
[/TR]
[TR]
[TD="align: right"]28[/TD]
[TD]MyRange.Copy[/TD]
[/TR]
[TR]
[TD="align: right"]29[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]30[/TD]
[TD]'Pegar informacion en nuevo documento[/TD]
[/TR]
[TR]
[TD="align: right"]31[/TD]
[TD]Workbooks(NuevoLibro).Activate[/TD]
[/TR]
[TR]
[TD="align: right"]32[/TD]
[TD]Sheets(1).Activate[/TD]
[/TR]
[TR]
[TD="align: right"]33[/TD]
[TD]Range("a1").Select[/TD]
[/TR]
[TR]
[TD="align: right"]34[/TD]
[TD]Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False[/TD]
[/TR]
[TR]
[TD="align: right"]35[/TD]
[TD]ActiveWorkbook.SaveAs Filename:="RD2-" & Range("D2").Value & " " & Range("C2").Value & " " & Range("B2").Value & " Incidentes Atendidos en el Día", FileFormat:=xlWorkbookNormal[/TD]
[/TR]
[TR]
[TD="align: right"]36[/TD]
[TD]ActiveWorkbook.Close[/TD]
[/TR]
[TR]
[TD="align: right"]37[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]38[/TD]
[TD]End Sub[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
If you want a variable instead of the cells value then this should do it

Code:
[TABLE="class: cms_table"]
<tbody>[TR]
[TD]Sheets("Sheet1").Range("tabla1").AutoFilter Field:=4, Criteria1:= variablenamehere[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top