Need to delete or over-write existing column if it already exists
Posted on 2011-04-20
I need to modify this code so that it either over-writes or deletes the Month_Year column if it already exists. The original code finds the last column and then adds a column named Month_Year with a formula value for all its cells.
Dim i As Long, r As Long, c As Long, MySheets
MySheets = Array("Sheet1", "Sheet2", "Sheet99") '<<=== adjust sheet names as needed
For i = 0 To UBound(MySheets)
r = .Range("h" & .Rows.Count).End(xlUp).Row
c = .UsedRange.Find("*", .[a1], , , 2, 2).Column
.Cells(1, c + 1).Value = "Month_Year"
.Cells(2, c + 1).Resize(r - 1).Formula = "=date(h2,i2,1)"