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.

[TABLE="width: 500"]
<tbody>[TR]
[TD]Date (data to find)[/TD]
[TD]User (data to export)[/TD]
[/TR]
[TR]
[TD]05/01/2019[/TD]
[TD]nforti[/TD]
[/TR]
[TR]
[TD]05/01/2019[/TD]
[TD]nforti[/TD]
[/TR]
[TR]
[TD]05/09/2019[/TD]
[TD]mpedrido[/TD]
[/TR]
[TR]
[TD]
05/09/2019
<strike></strike>
[/TD]
[TD]jberisso[/TD]
[/TR]
[TR]
[TD]
05/09/2019
<strike></strike>
[/TD]
[TD]amoreno[/TD]
[/TR]
[TR]
[TD]
05/09/2019
<strike></strike>
[/TD]
[TD]rdragun[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Thank you very much in advance for your help!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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