Adding three rows based on date change

Scarlacc

New Member
Joined
Apr 29, 2022
Messages
14
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Evening I have a list that I need to add three rows everything date changes in Column E. I have one that I found works to enter 1 row each value change. Here is what list rows look like.


A. B. C. D. E LOAD # CUST # CARRIER. TRLR # DATE



A Contains a 6 digit #
B 14 digit #
C Carrier Name
D usually no more then a 5 digit #
E Date it will already be sorted in order
Date format is mm/dd/yyyy

No headers added yet so starting right at top of sheet. On average contains range of 100 rows befor I sort anything. Only cells that have blank spots in the list is the trlr # in col D. Here is code im using probably a better method but kinda new to coding excel. Any help would be appreciated.
Added picture not near computer to get a good shot tho.


Sub InsertBlankRow()
Dim rowCount As Long
rowCount = 1 'set to start row

Do

check if dates are different
If (Cells(rowCount, "E") <> Cells(rowCount + 1, "E")) Then

'if they are then add a row
Rows(rowCount + 1).Select
Selection.Insert Shift:=xlDown

'and move on beyond the new blank row
rowCount = rowCount + 2

Else
'otherwise move on to next row
rowCount = rowCount + 1
End If
'if running through list until no more then
Loop Until IsEmpty(Cells(rowCount + 1, "E"))
 

Attachments

  • 20220429_092905.jpg
    20220429_092905.jpg
    216.4 KB · Views: 4

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Could be a solution:
VBA Code:
Option Explicit
Sub InsertBlankRows()
    Dim rowCount As Long
    rowCount = 1                                  'set to start row
    Do
        'check if dates are different
        If (Cells(rowCount, "E") <> Cells(rowCount + 1, "E")) Then
            'if they are then add 3 rows
            Rows(rowCount + 1 & ":" & rowCount + 3).Insert Shift:=xlDown '<-- changed
            'and move on beyond the new blank row
            rowCount = rowCount + 4                                      '<-- changed
        Else
            'otherwise move on to next row
            rowCount = rowCount + 1
        End If
        'if running through list until no more then
    Loop Until IsEmpty(Cells(rowCount + 1, "E"))
End Sub
 
Upvote 0
Solution
Could be a solution:
VBA Code:
Option Explicit
Sub InsertBlankRows()
    Dim rowCount As Long
    rowCount = 1                                  'set to start row
    Do
        'check if dates are different
        If (Cells(rowCount, "E") <> Cells(rowCount + 1, "E")) Then
            'if they are then add 3 rows
            Rows(rowCount + 1 & ":" & rowCount + 3).Insert Shift:=xlDown '<-- changed
            'and move on beyond the new blank row
            rowCount = rowCount + 4                                      '<-- changed
        Else
            'otherwise move on to next row
            rowCount = rowCount + 1
        End If
        'if running through list until no more then
    Loop Until IsEmpty(Cells(rowCount + 1, "E"))
End Sub
I will give it a try at work tonight
 
Upvote 0
For sure :giggle:. Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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