VBA- Insert 3 blank rows based on date

Status
Not open for further replies.

DynamiteHack

Board Regular
Joined
Jan 14, 2012
Messages
60
I have run into a bit of a wall with this one...I have a list of items that were printed and a date timestamp on each line. My goal is to scan down the rows and insert 3 blank rows after each date change.
I have found a way to insert a blank row after unique values. Code is below. ..

Code:
Sub insertem()
    Dim r As Long
    For r = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
        If range("J" & r).Value <> range("J" & r - 1) Then
            Rows(r).Insert
        End If
     Next r
End Sub



Unfortunately, this code inserts a blank row after every line because of the time portion of the stamp and I believe it is compared to the data in column A. This isn't exactly what I'm trying to do, but it got me closer. The trouble that I'm having is figuring out a strategy of looking at just the date portion of the stamp and inserting the blank rows between different dates. Here is a snippet of data, any advice would be much appreciated!!

[TABLE="width: 336"]
<tbody>[TR]
[TD="width: 88"]PickList[/TD]
[TD="width: 88"]GOOD[/TD]
[TD="class: xl65, width: 160, align: right"]10/6/2014 16:49[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/6/2014 16:49[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/6/2014 16:49[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/6/2014 16:49[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/6/2014 16:49[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/7/2014 9:00[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/7/2014 9:00[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/7/2014 9:00[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/7/2014 9:00[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/7/2014 9:00[/TD]
[/TR]
[TR]
[TD]PickList[/TD]
[TD]GOOD[/TD]
[TD="class: xl65, align: right"]10/7/2014 9:00[/TD]
[/TR]
</tbody>[/TABLE]
 
Thank you for getting back, we’ll ideally what you see in Column D will stay in Column D with and any date changes to the day earlier will remain in the same place.
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I love how you help me get the space between the dates. I managed through VBA to add a column headers to the first batch of days. How hard would it be to have those column headers listed on the rows for the next day and so on? The header columns are easy because they’re not going to budge, it’s the subsequent ones for the rows will change in height.
 
Upvote 0
I feel uneasy asking this, but I've been stuck on one other thing. I assure you I already have 9 macros now for this project I'm working on. The product now is really starting to take form.
In any case the question I have and it would be nice if you can offer any advice. The Column D , the one with the date and time are listed in GMT or Zulu time therefore I need to subtract 7 hours. The first one listed is 15 Oct 2020 0245 which means it will also change the date to 14 Oct. I'm looking for a code to change the time and if applicable the date will also move back. Once this is done then the blank rows will be inserted which we just did, then I'm going to remove the date and just leave the 24 hour time.

The formula I have which I know is way off is

VBA Code:
Sub Roll_Call()

Dim Roll_Call As Date

Roll_Call = "mm.dd.yyyy hh:mm"

Range("D1") = DateAdd("mm.dd.yyyy hh:mm", -7, Roll_Call)

End Sub
This is a duplicate to Subtract 7 hours from time using the mm.dd.yyyy hh:mm
Please do not post the same question multiple times. See #12 of the Forum Rules and points 6 & 7 of the Guidelines.

Any bumps, clarifications, or follow-ups should be posted to the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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