Forum Discussion
tanmanflanjan
Jun 12, 2021Copper Contributor
Help needed: aligning dates in multiple colums.
I'm doing an event study on stock returns. I have created a dataset with stock returns, but because they trade on different exchanges the dates don't always match. Is it possible to align the dates t...
HansVogelaar
Jun 12, 2021MVP
If you don't have Microsoft 365:
It is currently impossible to insert rows since each column contains a single array formula. Therefore, the following macro replaces the formulas with their values, then inserts row.
Sub MatchDates()
Dim r As Long
Dim m As Long
Dim c As Long
Dim n As Long
Application.ScreenUpdating = False
m = Cells(Rows.Count, 1).End(xlUp).Row
n = Cells(1, Columns.Count).End(xlToLeft).Column
With Cells(1, 1).Resize(m, n)
.Value = .Value
End With
For c = 2 To n - 1 Step 2
For r = 2 To m
If Cells(r, c).Value > Cells(r, 1).Value Then
Cells(r, c).Resize(1, 2).Insert Shift:=xlShiftDown
End If
Next r
Next c
Application.ScreenUpdating = True
End Sub