VBA Inputbox to find and select a Date Range

NicoForti

New Member
Joined
May 9, 2019
Messages
2
Hi everyone!
I'm having some difficulties to find the correct code to do this.
The workbook is pretty basic, it has a unique userform to enter data. I need an inputbox to prompt the user to specify a date and export it to a text file.
All the data from the userform goes to one sheet ("CAE") and i just need to export the B column.

For this example: i need to lookup for all the entries "05/09/2019" and export the users of only those dates.

Date (data to find)User (data to export)
05/01/2019nforti
05/01/2019nforti
05/09/2019mpedrido
05/09/2019
<strike></strike>
jberisso
05/09/2019
<strike></strike>
amoreno
05/09/2019
<strike></strike>
rdragun

<tbody>
</tbody>

Thank you very much in advance for your help!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this

Code:
Sub Macro3()
    Dim dat As Variant, lr As Long, sh As Worksheet
    
    Set sh = Sheets("CAE")
    dat = InputBox("Enter date mm/dd/yyyy : ")
    If dat = "" Then Exit Sub
    lr = sh.Range("A" & Rows.Column).End(xlUp).Row
    If sh.AutoFilterMode Then sh.AutoFilterMode = False
    sh.Range("A1:B" & lr).AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, dat)
    Set wb = Workbooks.Add
    sh.AutoFilter.Range.Columns(2).Copy wb.Sheets(1).Range("A1")
    If sh.AutoFilterMode Then sh.AutoFilterMode = False
End Sub
 
Upvote 0
Dante, muchas gracias!
Lo que necesitaría es que lo que copia de la columna B, lo exporte en TXT.

Try this

Code:
Sub Macro3()
    Dim dat As Variant, lr As Long, sh As Worksheet
    
    Set sh = Sheets("CAE")
    dat = InputBox("Enter date mm/dd/yyyy : ")
    If dat = "" Then Exit Sub
    lr = sh.Range("A" & Rows.Column).End(xlUp).Row
    If sh.AutoFilterMode Then sh.AutoFilterMode = False
    sh.Range("A1:B" & lr).AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, dat)
    Set wb = Workbooks.Add
    sh.AutoFilter.Range.Columns(2).Copy wb.Sheets(1).Range("A1")
    If sh.AutoFilterMode Then sh.AutoFilterMode = False
End Sub
 
Upvote 0
Listo, cambia "Libro6.txt" por el nombre del archivo

Code:
Sub Macro3()
    Dim dat As Variant, lr As Long, sh As Worksheet
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set sh = Sheets("CAE")
    dat = InputBox("Enter date mm/dd/yyyy : ")
    If dat = "" Then Exit Sub
    lr = sh.Range("A" & Rows.Column).End(xlUp).Row
    If sh.AutoFilterMode Then sh.AutoFilterMode = False
    sh.Range("A1:B" & lr).AutoFilter Field:=1, Operator:=xlFilterValues, Criteria2:=Array(2, dat)
    Set wb = Workbooks.Add
    sh.AutoFilter.Range.Columns(2).Copy wb.Sheets(1).Range("A1")
    ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & "[COLOR=#ff0000]Libro6.txt[/COLOR]", FileFormat:=xlTextMSDOS, CreateBackup:=False
    ActiveWorkbook.Close False
    If sh.AutoFilterMode Then sh.AutoFilterMode = False
    MsgBox "Archivo txt generado"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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