Segregation of Dates based on DOW (Numeric)

shansakhi

Active Member
Joined
Apr 5, 2008
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hello Everybody,
Need your assistance.
Is there a way we can segregates dates based on DOW (Day of week - numeric).
The data can come in any format.
Below sample data for your reference...

RAW DATA (Here DOW numeric = 1-MON,2-TUE, 3-WED,4-THU,5-FRI,6-SAT,7-SUN)

INPUT OUTPUT
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Eff Date[/TD]
[TD]Dis Date[/TD]
[TD]DOW[/TD]
[TD]Date[/TD]
[TD]DOW[/TD]
[/TR]
[TR]
[TD]28-Dec-18[/TD]
[TD]31-Dec-18[/TD]
[TD]15[/TD]
[TD]28-Dec-18[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]31-Dec-18[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]13-Dec-18[/TD]
[TD]16-Dec-18[/TD]
[TD]457[/TD]
[TD]13-Dec-18[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]14-Dec-18[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]16-Dec-18[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]5-Dec-18[/TD]
[TD]6-Dec-18[/TD]
[TD]34[/TD]
[TD]5-Dec-18[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]6-Dec-18[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]24-Dec-18[/TD]
[TD]31-Dec-18[/TD]
[TD]1357[/TD]
[TD]24-Dec-18[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]26-Dec-18[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]28-Dec-18[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]30-Dec-18[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]31-Dec-18[/TD]
[TD]1[/TD]
[/TR]
</tbody>[/TABLE]
Thank you in Advance.

Regards,
Shan
 
Hi,
Need you help.
The code is working fine. Currently its providing output in D and E column.. Is it possible to provide this output end of all used column.

OK, try this :

Code:
[FONT=lucida console][COLOR=Royalblue]Sub[/COLOR] a1076113b()
[I][COLOR=seagreen]'https://www.mrexcel.com/forum/excel-questions/1076113-segregation-dates-based-dow-numeric.html[/COLOR][/I]
[COLOR=Royalblue]Dim[/COLOR] i [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], j [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], k [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], q [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], g [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR]
[COLOR=Royalblue]Dim[/COLOR] va [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Variant[/COLOR], vb [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Variant[/COLOR], vc [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Variant[/COLOR]
[COLOR=Royalblue]Dim[/COLOR] stDate [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Date[/COLOR], enDate [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Date[/COLOR], d [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Date[/COLOR]


rc = Cells([COLOR=crimson]1[/COLOR], Columns.count).[COLOR=Royalblue]End[/COLOR](xlToLeft).Column
ra = Range([COLOR=brown]"A"[/COLOR] & Rows.count).[COLOR=Royalblue]End[/COLOR](xlUp).Row
va = Range(Cells([COLOR=crimson]2[/COLOR], [COLOR=brown]"A"[/COLOR]), Cells(ra, rc))

[COLOR=Royalblue]ReDim[/COLOR] vb([COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]1[/COLOR]) * [COLOR=crimson]10[/COLOR], [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] [COLOR=crimson]2[/COLOR])
[COLOR=Royalblue]ReDim[/COLOR] vc([COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]1[/COLOR]) * [COLOR=crimson]10[/COLOR], [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]2[/COLOR]))

[COLOR=Royalblue]For[/COLOR] i = [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]1[/COLOR])
    stDate = va(i, [COLOR=crimson]1[/COLOR])
    enDate = va(i, [COLOR=crimson]2[/COLOR])
      [COLOR=Royalblue]For[/COLOR] d = stDate [COLOR=Royalblue]To[/COLOR] enDate
            q = Weekday(d) - [COLOR=crimson]1[/COLOR]
            [COLOR=Royalblue]If[/COLOR] q = [COLOR=crimson]0[/COLOR] [COLOR=Royalblue]Then[/COLOR] q = [COLOR=crimson]7[/COLOR]
                [COLOR=Royalblue]If[/COLOR] q [COLOR=Royalblue]Like[/COLOR] [COLOR=brown]"["[/COLOR] & Trim(va(i, [COLOR=crimson]3[/COLOR])) & [COLOR=brown]"]"[/COLOR] [COLOR=Royalblue]Then[/COLOR]
                    j = j + [COLOR=crimson]1[/COLOR]
                    k = k + [COLOR=crimson]1[/COLOR]
                    vb(j, [COLOR=crimson]1[/COLOR]) = d
                    vb(j, [COLOR=crimson]2[/COLOR]) = q
                [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
      [COLOR=Royalblue]Next[/COLOR]
        
    [COLOR=Royalblue]For[/COLOR] g = [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]2[/COLOR])
    vc(j - k + [COLOR=crimson]1[/COLOR], g) = va(i, g)
    [COLOR=Royalblue]Next[/COLOR]
        k = [COLOR=crimson]0[/COLOR]
[COLOR=Royalblue]Next[/COLOR]
Range([COLOR=brown]"A2"[/COLOR]).Resize([COLOR=crimson]1[/COLOR], rc).Copy
Range([COLOR=brown]"A2"[/COLOR]).Resize(j, rc).PasteSpecial xlPasteFormats
Range([COLOR=brown]"A2"[/COLOR]).Copy
Cells([COLOR=crimson]2[/COLOR], rc + [COLOR=crimson]1[/COLOR]).Resize(j, [COLOR=crimson]1[/COLOR]).PasteSpecial xlPasteFormats
Range([COLOR=brown]"A2"[/COLOR]).Resize(j, rc) = vc
Cells([COLOR=crimson]2[/COLOR], rc + [COLOR=crimson]1[/COLOR]).Resize(j, [COLOR=crimson]2[/COLOR]) = vb

[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Wow! You are really great !! It's working exactly as desired !! Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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