Insert blank row if more than same month date - VBA

adino8

New Member
Joined
Mar 20, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi guys
Here's my problem
I'm trying to insert blank row in my data sheet in every group number given (ex. before 2 or 5 rows) based on month.
It will insert new blank row if there's more than one same month date (ex. September) and if there is another month (ex. October) it will start counting based on new month and insert new blank row only if more than one October date' appears.

I have this:
17-01-2022 - Daty i sumy spłat w PLN i CHF.xlsx
ABCD
1DataWysokość raty kapitałowej w CHFWysokość raty odsetkowej w CHFRazem rata kapitałowo - odsetkowa w CHF
212 lip 060.00 CHF257.74 CHF257.74 CHF
331 lip 06885.98 CHF1,551.89 CHF2,437.87 CHF
430 sie 06883.24 CHF1,547.24 CHF2,430.48 CHF
51 wrz 060.00 CHF0.00 CHF0.00 CHF
62 paź 06899.86 CHF1,543.65 CHF2,443.51 CHF
76 lis 06865.09 CHF1,636.90 CHF2,501.99 CHF
81 gru 06868.60 CHF1,580.37 CHF2,448.97 CHF
92 sty 07873.02 CHF1,629.23 CHF2,502.25 CHF
1024 sty 07830.88 CHF1,651.83 CHF2,482.71 CHF
1119 lut 078.07 CHF0.01 CHF8.08 CHF
1226 lut 0710.26 CHF8.41 CHF18.67 CHF
136 mar 07853.22 CHF1,705.73 CHF2,558.95 CHF
143 kwi 07857.25 CHF1,791.49 CHF2,648.74 CHF
Arkusz
Cell Formulas
RangeFormula
D2:D4,D6:D14D2=B2+C2


I want to be like this:
17-01-2022 - Daty i sumy spłat w PLN i CHF.xlsx
ABCD
1DataWysokość raty kapitałowej w CHFWysokość raty odsetkowej w CHFRazem rata kapitałowo - odsetkowa w CHF
2
312 lip 060.00 CHF257.74 CHF257.74 CHF
431 lip 06885.98 CHF1,551.89 CHF2,437.87 CHF
530 sie 06883.24 CHF1,547.24 CHF2,430.48 CHF
61 wrz 060.00 CHF0.00 CHF0.00 CHF
72 paź 06899.86 CHF1,543.65 CHF2,443.51 CHF
86 lis 06865.09 CHF1,636.90 CHF2,501.99 CHF
91 gru 06868.60 CHF1,580.37 CHF2,448.97 CHF
10
112 sty 07873.02 CHF1,629.23 CHF2,502.25 CHF
1224 sty 07830.88 CHF1,651.83 CHF2,482.71 CHF
13
1419 lut 078.07 CHF0.01 CHF8.08 CHF
1526 lut 0710.26 CHF8.41 CHF18.67 CHF
166 mar 07853.22 CHF1,705.73 CHF2,558.95 CHF
173 kwi 07857.25 CHF1,791.49 CHF2,648.74 CHF
Arkusz
Cell Formulas
RangeFormula
D3:D5,D14:D17,D11:D12,D7:D9D3=B3+C3


Can you help me guys. Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Have a try with my macro (it will check if same month but not if different year) to be pasted in a vbe module:
VBA Code:
Option Explicit
Sub InsertBlankRow()
    Dim lr     As Long
    Dim ar     As Long
    Dim ar2    As Long
    Dim flag   As Boolean
    Application.ScreenUpdating = False
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For ar = lr To 3 Step -1
        ar2 = ar
        If Month(Range("A" & ar)) = Month(Range("A" & ar2 - 1)) Then
            flag = True
            Do
                ar2 = ar2 - 1
                If ar2 > 2 Then
                    If Month(Range("A" & ar)) = Month(Range("A" & ar2 - 1)) Then
                        ar2 = ar2 - 1
                    Else
                        flag = False
                    End If
                End If
                flag = False
            Loop Until flag = False
            Range("A" & ar2).EntireRow.Insert Shift:=xlDown
            Range("A" & ar2).EntireRow.ClearFormats
            ar = ar2
        End If
    Next ar
    Application.ScreenUpdating = True
    MsgBox "Done!"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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