Hi all!
For a dynamic analysis, I need to add a new column to my data set every month. This new column should continue the formula from the column to the left of it, e.g. one column contains the formula: "=EOMONTH(P2;1)", which should then become "EOMONTH(Q2;1)" in the new column to the right of it.
Since there are several analyses on the sheet, I cannot search for the last column, but I search for a term "[1]", next to which a new column is to be inserted and the formula from the column to the left is to be dragged into this new column. This way, I can always search for the same term, as it always moves along.
The data record looks something like this:
I have the code so far that it finds the term "[1]" and inserts a column to the left of it, but now I can't get the formula there.
Hier der Code:
Dim ow As Worksheet
Dim rng1 As Range
Dim TargetCol As Range
Dim SourceCol As Range
Set ow = ThisWorkbook.Sheets("Overview")
Set rng1 = ow.Cells.Find("[1]", LookIn:=xlValues)
ow.Range(rng1, ow.Cells(ow.Rows.Count, rng1.Column)).EntireColumn.Insert
Set TargetCol = rng1.Offset(0, -1)
Set SourceCol = rng1.Offset(0, -2)
SourceCol.AutoFill Destination:=TargetCol, Type:=xlFillDefault
TargetCol.Formula = "=" & SourceCol.Address
Thanks a lot in advance!
For a dynamic analysis, I need to add a new column to my data set every month. This new column should continue the formula from the column to the left of it, e.g. one column contains the formula: "=EOMONTH(P2;1)", which should then become "EOMONTH(Q2;1)" in the new column to the right of it.
Since there are several analyses on the sheet, I cannot search for the last column, but I search for a term "[1]", next to which a new column is to be inserted and the formula from the column to the left is to be dragged into this new column. This way, I can always search for the same term, as it always moves along.
The data record looks something like this:
[1] | |||
01/01/2024 | 01/02/2024 | 01/03/2024 | |
1 | 1 | 1 | |
2 | 2 | 2 | |
3 | 3 | 3 | |
4 | 4 | 4 | |
5 | 5 | 5 |
I have the code so far that it finds the term "[1]" and inserts a column to the left of it, but now I can't get the formula there.
Hier der Code:
Dim ow As Worksheet
Dim rng1 As Range
Dim TargetCol As Range
Dim SourceCol As Range
Set ow = ThisWorkbook.Sheets("Overview")
Set rng1 = ow.Cells.Find("[1]", LookIn:=xlValues)
ow.Range(rng1, ow.Cells(ow.Rows.Count, rng1.Column)).EntireColumn.Insert
Set TargetCol = rng1.Offset(0, -1)
Set SourceCol = rng1.Offset(0, -2)
SourceCol.AutoFill Destination:=TargetCol, Type:=xlFillDefault
TargetCol.Formula = "=" & SourceCol.Address
Thanks a lot in advance!