Hello everyone
I was searching around, but wasn't able to find a solution for my problem.
I have the following list:
Now what I need is to check the cell value in column C if the entries are still in the same month, if not add a new row above that cell and write the corresponding month into column A.
It should look like this:
I found the following code, which adds new rows if the date changes, but I can't make it work to check only the month.
Any help is appreciated. Thanks in advance
I was searching around, but wasn't able to find a solution for my problem.
I have the following list:
Datalist.xlsx | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Title A | Title B | Date | ||
2 | 123456 | A | 2020/12/7 | ||
3 | 1234567 | B | 2020/12/15 | ||
4 | 123456778 | C | 2021/1/1 | ||
5 | 87654321 | M | 2021/1/1 | ||
6 | 987654321 | G | 2021/12/14 | ||
Sheet1 |
Now what I need is to check the cell value in column C if the entries are still in the same month, if not add a new row above that cell and write the corresponding month into column A.
It should look like this:
Book1 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Title A | Title B | Date | ||
2 | December | ||||
3 | 123456 | A | 2020/12/7 | ||
4 | 1234567 | B | 2020/12/15 | ||
5 | January | ||||
6 | 123456778 | C | 2021/1/1 | ||
7 | 87654321 | M | 2021/1/1 | ||
8 | April | ||||
9 | 987654321 | G | 2021/4/14 | ||
Sheet1 |
I found the following code, which adds new rows if the date changes, but I can't make it work to check only the month.
VBA Code:
Sub InsertAtDateChange()
Dim lastRow, chkRw As Integer
lastRow = Range("C" & Rows.Count).End(xlUp).Row
For chkRw = lastRow To 1 Step -1
If Range("C" & chkRw) <> Range("C" & chkRw + 1) Then
Range("C" & chkRw + 1).EntireRow.Insert shift:=xlDown
End If
Next
End Sub
Any help is appreciated. Thanks in advance