Creating a list of specific dates from a weekly date range

killeen

New Member
Joined
Apr 30, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hello,

So I have a large spreadsheet where each row represents a date range for a specific event that happens on specific days of the week. Here are some examples:

1660258998985.png


How do I pull out each applicable date from each date range using Excel or other functionality? Any insight to give me some ideas would be greatly appreciated. Thanks in advance.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The request is too vague, so I assumed you would like to select one line of the table and get in a columns of your sheet the list of dates for that event.
Also I request that your "Days" are expressed in a more suitable form, ie a list of weekdays such as
1 for Monday
2 for Tuesday
1,2,3,5 for Monday, Tuesday, Wednesday, Friday

Let's suppose this is in column G

Now rightclick on the tab with the name of the worksheet with the table; select Display Code; this will open the editor of the macro at "the right position"
Copy the following code and paste it into the empty right frame of the editor:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim FreeCol As Long, RuleC As Long, CInd As Long
'
FreeCol = 10            '<<< 10=J
RuleC = 7               '<<< 7=G
With Target.Range("A1")
    If .Column = 2 Then
        If IsDate(.Value) Then
            Columns(FreeCol).ClearContents
            mysplit = Split(Replace(.Offset(0, RuleC - 2).Value, " ", "") & ",9,", ",", , vbTextCompare)
            For i = .Value To .Offset(0, 1).Value
                If Not IsError(Application.Match(Weekday(i, vbMonday) & "", mysplit, False)) Then
                    CInd = CInd + 1
                    Cells(CInd, FreeCol).Value = CDate(i)
                End If
            Next i
        End If
    End If
End With
End Sub

Edit the two lines marked <<<:
FreeCol is the column where the result will be written; 10 means J
RuleC is the column where the "event days" are written as sequence of numbers as sayd before; 7 means G

Now return to the worksheet and select a date in column B: the dates with that event will be listed in column J (if FreeCol=10), as shown in the attached image
(the weekday in column K is obtained using the formula shown in column L)

Hope this give you some useful insights...
 

Attachments

  • KILLEEN_Immagine 2022-08-12 154631.jpg
    KILLEEN_Immagine 2022-08-12 154631.jpg
    62.3 KB · Views: 2
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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