Macro to insert rows based on Date and Time Cell

Foxvh

New Member
Joined
Jul 9, 2020
Messages
14
Office Version
  1. 2010
Platform
  1. Windows
Hi,

i have a report which inputs rows of data into a (To Be Allocated) sheet and would like to have these sorted by Date and Time Allocated using a macro that places them below a merged row with the date as the header based on Date Cell (A:A) and then sorts the rows underneath the date header by time (E:E).

columns
Date (A:A)
Time (E:E)

any help or guidance would be much appreciated.

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Just to clarify,
is your data like this? In which line do your data start? do you have headers
varios 10jul2020.xlsm
ABCDE
1DATETIME
208-jul10:00
308-jul11:00
408-jul12:00
508-jul13:00
608-jul14:00
709-jul15:00
809-jul16:00
909-jul17:00
1010-jul18:00
Start


Do you want this result?
varios 10jul2020.xlsm
ABCDE
1DATETIME
208-jul
308-jul10:00
408-jul11:00
508-jul12:00
608-jul13:00
708-jul14:00
809-jul
909-jul15:00
1009-jul16:00
1109-jul17:00
1210-jul
1310-jul18:00
End
 
Upvote 0
Hi Dante,

Apologies for the late response.

Yes the layout on the bottom one is correct.
The headers are columns A-N.
A,B,E will be blank for manual input (Date,Number,Time) where as every other column will have data input automatically from another sheet.

Thank you for your help.
 
Upvote 0
Sorry, but I still don't understand how your data is and how you want the output.
Could you put the examples now, use XL2BB tool, see my signature.
 
Upvote 0
Sorry i'm using a work PC so i'm not able to install XL2BB i hope the below will be okay.


1594701238417.png
 
Upvote 0
You forgot the image of how your input data is, it is very obvious to you because you are viewing your data.
But before doing any code you could put an image of your sheet with data (replace your data with generic data)
What is the name of your data sheet and your destination sheet?
 
Upvote 0
The below image is the sheet where data will be input from called ( To Be Allocated) the sheet it will be input to is called (Schedule)
wish i could just link the whole sheet but the data is confidential.

1594789460557.png
 
Upvote 0
I'm sorry I do not understand.
On the "To Be Allocated" sheet in column A you have the date 8jul.
On the "Schedule" sheet in row 2 you want "WEB 8/7".
- Where do I get "WEB"?
- Then there are 13 blank rows, are there always 13 rows between each date?
 
Upvote 0
Sorry that's a typo it is supposed to be WEN 8/07 (DDD D/MM) which is the date display format, how that date is formatted doesn't really bother to me so can be changed if needed.

for each date there is a merged row (Purple) that the data lines are to be separated in too and a maximum of 15 lines of data below that date row.
 
Upvote 0
Try this

VBA Code:
Sub Insert_Rows_Based_Date()
  Dim sh As Worksheet
  Dim i As Long, j As Long
  
  Set sh = Sheets("To Be Allocated")
  j = 2
  
  With Sheets("Schedule")
    .Rows("2:" & Rows.Count).Clear
    For i = 2 To sh.Range("A" & Rows.Count).End(3).Row
      With .Range("A" & j & ":N" & j)
        .Merge
        .Value = sh.Range("A" & i).Value
        .NumberFormat = "ddd d/mm"
        .HorizontalAlignment = xlCenter
      End With
      j = j + 16
    Next
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
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