VBA UserForm: Filter data in between dates using sheet name (FYI: i have multiple sheets, around 20-30 of them)

wcanarejo

New Member
Joined
Jun 5, 2021
Messages
9
Hi everyone,

I am new to Excel VBA, and I have some issues filtering data in between dates.
I Just want to be able to filter entries (from date-to date) using the sheetname as a criteria.

This is how the form look like( please see attached photo)


Or if you have any way get this sorted out, please do suggest. I really need your help.
Thank you very much
 

Attachments

  • sheet viewing.PNG
    sheet viewing.PNG
    38.6 KB · Views: 6

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Ive been looking for this online but I cant find one.
By the way this is a DTR, and I just want to filter by date and sum up time in timeout of the employee ang get their total hours for the entire week
 
Upvote 0
It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).

Hi mumps,
This is an xlb22 of my sheet.

DataEntry.xlsb
ABCDEFGHIJ
1No.ID No.EmployeeDateTime InTime OutBreakTotal HoursSite LocationLogged Activities
211002Nino Yec06/03/217:00AM17:00PM0.39.714 Bauchop6/3/2021 20:24
321004Emmanuel Marzan06/02/217:00AM15:00PM0.57.5BellRoad6/4/2021 5:27
431005Marvel Domingues06/02/216:00AM14:00PM0.57.514 Bauchop6/4/2021 5:29
541007Romeo Bandivas06/05/218:00AM16:00PM0827 Waiwhetu6/4/2021 5:30
651003Ruffin Cortes06/02/215:00AM13:00PM0.37.7Red Cross6/4/2021 5:31
761003Ruffin Cortes06/05/216:00AM15:00PM0.58.5148 Riverside6/4/2021 7:07
871003Nino Yec06/05/216:00AM14:00PM0.57.5318 Oxford Terrace6/4/2021 18:32
981004Efren Galang06/04/216:00AM14:00PM0.57.5Red Cross6/4/2021 18:35
1091004Efren Galang06/07/207:00AM15:00PM0.57.5176 Cambridge6/4/2021 21:17
11101006oleg05/05/217:00AM15:00PM08176 Cambridge6/5/2021 4:43
12111003Nino Yec06/01/214:00AM16:00PM012176 Cambridge6/5/2021 6:54
13121003Nino Yec06/02/215:00AM16:00PM0.510.514 Bauchop6/5/2021 6:55
14131002Ruffin Cortes06/07/212:00AM14:00PM0.511.514 Bauchop6/5/2021 18:10
15141002Ruffin Cortes06/01/216:00AM15:00PM0.58.514 Bauchop6/5/2021 18:13
16151002Ruffin Cortes06/03/213:00AM13:00PM0.59.5Red Cross6/5/2021 18:14
17161002Ruffin Cortes06/04/207:00AM12:00PM05148 Riverside6/5/2021 18:14
18171002Ruffin Cortes06/04/2113:00PM16:00PM03Red Cross6/5/2021 18:16
Data
Cell Formulas
RangeFormula
A4:A18A4=ROW()-1
 
Upvote 0
I assigned 1 sheet for the employee dedicated for their time entries. So every time I am adding an entry, it will be double saved from this sheet to the sheet named after them. I think it's a bit redundant, but if you could help me simplify this.
 
Upvote 0
Thank you for the sheet data. However, in your original post, you had a drop down list of sheet names, date from, date to and a command button. I don't see these in Post #4. Are you using a userform which contains this data? If so, I would need access to the userform. It might be easier if you uploaded a copy of your file to box.com or dropbox.com and posted the link here.
 
Upvote 0
Thank you for the sheet data. However, in your original post, you had a drop down list of sheet names, date from, date to and a command button. I don't see these in Post #4. Are you using a userform which contains this data? If so, I would need access to the userform. It might be easier if you uploaded a copy of your file to box.com or dropbox.com and posted the link here.
Yes I am using a userform. Those data assigned to the dropdownlist are the name of the sheets I have in this workbook. I am doing a double saving method to be able to save selected on the sheets named after them. Let me show you a sample.
DataEntry.xlsb
ABCD
1DateID NoNameTotal Hrs
26/2/20211002Ruffin Cortes8
36/7/20211002Ruffin Cortes11.5
46/1/20211002Ruffin Cortes8.5
56/3/20211002Ruffin Cortes9.5
66/4/21201002Ruffin Cortes5
76/4/20211002Ruffin Cortes3
Ruffin Cortes


this is a sheet named after this employee. What I want is that, whenever i go to the userform I made, I will chose their name on the dropdown, then the listbox will get the data from sheets that are name after the employee then from their I would be able to filter the data using date range filtering.

the dropdown process for each employee works fine, it perfectly pitching the data from their assigned sheets. the filtering by date is where im stuck at.
 
Upvote 0
I would need the names of the userform objects and also to see the code you are currently using. The easiest way to do this is to upload a copy of your file as I suggested in Post #3.
 
Upvote 0
Yeah, No big deal. Heres the Link. DataEntry.xlsb
Im just new to this so, if you can help me simplify it, that would be greatly appreciated. Thank you so much for your help.
 
Upvote 0
Replace your current code with this:
VBA Code:
Private Sub ComboBox1_Change()
    Me.ListBox1.Clear
    Me.Label6 = Sheets(ComboBox1.Value).Name
    TextBox1.SetFocus
End Sub

Private Sub TextBox1_AfterUpdate()
    Me.TextBox1 = CDate(Me.TextBox1)
    TextBox2.SetFocus
End Sub

Private Sub TextBox2_AfterUpdate()
    Application.ScreenUpdating = False
    Dim beginDate As Long, endDate As Long, srcWS As Worksheet, rng As Range, LastRow As Long, total As Double, C As Long
    Set srcWS = Sheets(ComboBox1.Value)
    Me.TextBox1 = CDate(Me.TextBox1)
    beginDate = DateValue(Me.TextBox1.Value)
    endDate = DateValue(Me.TextBox2.Value)
    ldatefrom = DateSerial(Day(beginDate), Month(beginDate), Year(beginDate))
    ldateto = DateSerial(Day(endDate), Month(endDate), Year(endDate))
    Me.ListBox1.Clear
    With srcWS
        LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        .Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:=">=" & CLng(beginDate), Operator:=xlAnd, Criteria2:="<=" & CLng(endDate)
        For Each rng In .Range("A1:A" & LastRow).SpecialCells(xlCellTypeVisible)
            If rng.Row > 1 Then
                total = total + rng.Offset(, 3).Value
            End If
            Me.ListBox1.AddItem
            For C = 0 To 3
                Me.ListBox1.List(ListBox1.ListCount - 1, C) = .Cells(rng.Row, C + 1)
            Next C
        Next rng
        .Range("A1").AutoFilter
        Label5.Caption = "Total Hours: " & total
    End With
    Application.ScreenUpdating = True
End Sub

Private Sub UserForm_Initialize()
    Dim i As Long
    For i = 2 To Sheets.Count
        Me.ComboBox1.AddItem Sheets(i).Name
    Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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