Filter Data As per Date

hashi2c

New Member
Joined
Jan 7, 2018
Messages
20
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
  3. Web
Can someone help me?

I want the data (Vessel Name) will be filtered automatically as per cell Date (04-Dec-2017)

Data Sheet
Vessel NameArrival DateDeparture Date
Vessel-101-Dec-201704-Dec-2017
Vessel-201-Dec-201702-Dec-2017
Vessel-301-Dec-201704-Dec-2017
Vessel-401-Dec-201708-Dec-2017
Vessel-502-Dec-201703-Dec-2017
Vessel-602-Dec-201703-Dec-2017
Vessel-702-Dec-201705-Dec-2017
Vessel-802-Dec-201702-Dec-2017

Report Sheet
Available vessels on the Date of04-Dec-2017
Vessel Name
Vessel-1
Vessel-3
Vessel-4
Vessel-7


Thank you in advance for all who helps and suggest.
 
Last edited by a moderator:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try this, Data in Sheet "Data Sheet" Results in Sheet "Report Sheet", when Date in "Report sheet " "B1" Changed.
NB:- The Header "Vessel Name" in sheet "Data Sheet" assumed to be in "A1"

Code:
Private [COLOR=navy]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR=navy]As[/COLOR] Range)
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, Dt [COLOR=navy]As[/COLOR] Date, Ray()
[COLOR=navy]Dim[/COLOR] C [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
C = 3
Application.EnableEvents = False
    [COLOR=navy]If[/COLOR] Target.Address(0, 0) = "B1" [COLOR=navy]Then[/COLOR]
        [COLOR=navy]With[/COLOR] Sheets("Data Sheet")
            [COLOR=navy]Set[/COLOR] Rng = .Range("B2", .Range("B" & Rows.Count).End(xlUp))
        [COLOR=navy]End[/COLOR] With
        Range("A4").Resize(Rng.Count).ClearContents
            [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
                [COLOR=navy]For[/COLOR] Dt = Dn To Dn.Offset(, 1)
                    [COLOR=navy]If[/COLOR] Dt = Target.Value [COLOR=navy]Then[/COLOR]
                        C = C + 1
                        Cells(C, 1) = Dn.Offset(, -1).Value
                    [COLOR=navy]End[/COLOR] If
                 [COLOR=navy]Next[/COLOR] Dt
            [COLOR=navy]Next[/COLOR] Dn
    [COLOR=navy]End[/COLOR] If
Application.EnableEvents = True
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]

NB:- How to:-
To Save and Run Code:-
Copy code from Thread
In Your sheet "Report Sheet" Click "Alt + F11",:- Vb Window appears.
Paste Code into this window.
Close Vbwindow.
When you now change value in "B1" the code should run and Column "A" should be updated.

Regrds Mick



Regards Mick
 
Last edited:
Upvote 0
Please post your reply back to this original Thread not a PM.
(1) Posting PM's to me only confuses the problem and breaks up the continuity of the Thread
(2) For some reason copying your data from the PM ,creates problems when pasting as the received data becomes garbled.
(3) NB:- You appear to have exceeded your Private message Quota.Please clear some messages !!!
 
Upvote 0
Hi Mick,

Thank You so much for your help, it's working perfectly with date, but i need to get Time difference also in same report sheet. is that possible?

Data Sheet


Vessel NameArrival Date & TimeDeparture Date & TimeTime Diff. (HRS)
Vessel-101-Dec-17 15:3004-Dec-17 01:1057:40
Vessel-201-Dec-17 16:0002-Dec-17 15:0023:00
Vessel-301-Dec-17 17:1004-Dec-17 14:2069:10
Vessel-401-Dec-17 17:3008-Dec-17 02:00152:30
Vessel-502-Dec-17 18:0003-Dec-17 05:4511:45
Vessel-602-Dec-17 18:4503-Dec-17 06:0011:15
Vessel-702-Dec-17 20:2005-Dec-17 23:0074:40
Vessel-802-Dec-17 21:0002-Dec-17 21:500:50
Report Sheet
Date :04-Dec-17
Available vessels on the Date of (B1)Time Diff. (HRS)
Vessel-101:10
Vessel-314:20
Vessel-424:00
Vessel-724:00

<tbody>
</tbody>
 
Upvote 0
Please explain the logic for Vessel-4 & Vessel_7 having a time difference of 24:00 ()hrs)
 
Upvote 0
Vessel-4 & Vessel-7 available full day on 4th Dec 2017
 
Upvote 0
Try this:-
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Dt [COLOR="Navy"]As[/COLOR] Date, Ray(), Tm [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] C [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
C = 3
Application.EnableEvents = False
    [COLOR="Navy"]If[/COLOR] Target.Address(0, 0) = "B1" [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]With[/COLOR] Sheets("Data Sheet")
            [COLOR="Navy"]Set[/COLOR] Rng = .Range("B2", .Range("B" & Rows.Count).End(xlUp))
        [COLOR="Navy"]End[/COLOR] With
        Range("A4").Resize(Rng.Count).ClearContents
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
                [COLOR="Navy"]For[/COLOR] Dt = DateValue(Dn) To DateValue(Dn.Offset(, 1))
                    [COLOR="Navy"]If[/COLOR] DateValue(Dt) = Target.Value [COLOR="Navy"]Then[/COLOR]
                        C = C + 1
                        Cells(C, 1) = Dn.Offset(, -1).Value
                        Tm = IIf(DateValue(Dn.Offset(, 1)) - Target.Value = 0, Format(Dn.Offset(, 1) - Target.Value, "hh:mm"), "24:00:00")
                        Cells(C, 2).NumberFormat = "General"
                        Cells(C, 2) = Tm
                    [COLOR="Navy"]End[/COLOR] If
                 [COLOR="Navy"]Next[/COLOR] Dt
            [COLOR="Navy"]Next[/COLOR] Dn
    [COLOR="Navy"]End[/COLOR] If
Application.EnableEvents = True
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi Mick,

Thanks for your quick response; it's very much appreciated,

If i put 02 Dec-17 need to get result as below, (I need know how many hours vessels consumed on selected date.
Date :
02-Dec-17
Available vessels on the Date of (B1)
Time Diff. (HRS)
Vessel-1
24:00
Vessel-2
15:00
Vessel-3
24:00
Vessel-4
24:00
Vessel-5
6:00
Vessel-6
5:15
Vessel-7
3:40
Vessel-8
0:50

<tbody>
</tbody>
 
Upvote 0
Try this:-
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, Dn As Range, Dt As Date, Ray(), Tm As String
Dim C As Long
C = 3
Application.EnableEvents = False
    If Target.Address(0, 0) = "B1" Then
        With Sheets("Data Sheet")
            Set Rng = .Range("B2", .Range("B" & Rows.Count).End(xlUp))
        End With
        Range("A4").Resize(Rng.Count, 2).ClearContents
            For Each Dn In Rng
                For Dt = DateValue(Dn) To DateValue(Dn.Offset(, 1))
                    If DateValue(Dt) = Target.Value Then
                        C = C + 1
                        Cells(C, 1) = Dn.Offset(, -1).Value
                       
                        Select Case True
                                Case DateValue(Dn.Offset(, 1)) - Target.Value = 0 And DateValue(Dn.Offset(, 1)) = DateValue(Dn.Value): Tm = Format(Dn.Offset(, 1) - Dn.Value, "hh:mm")
                                Case DateValue(Dn.Offset(, 1)) - Target.Value = 0: Tm = Format(Dn.Offset(, 1) - Target.Value, "hh:mm")
                                Case DateValue(Dn.Value) - Target.Value = 0: Tm = Format(24 - (Dn.Value - Target.Value), "hh:mm")
                                Case DateValue(Dn.Offset(, 1)) - Target.Value <> 0: Tm = "24:00:00"
                       End Select
                        Cells(C, 2).NumberFormat = "General"
                        Cells(C, 2) = Tm
                    End If
                 Next Dt
            Next Dn
    End If
Application.EnableEvents = True
End Sub
Regards Mick
 
Last edited by a moderator:
Upvote 0
Solution
Thanks for your help Mick, That works perfectly............:):cool:
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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