Dear arnelgp,
I've tried to replicate the same logic on another worksheet/table.
It seems working for the first loop of "For" condition, but at the end it is retrieving me an error.
Please see the code below:
Private Sub InitializeProject_Click()
Dim ws1, ws2, ws3, ws4 As Worksheet
Dim dur, dur2 As Variant
Dim i, j As Long
Dim table3, table4 As ListObject
Dim stdate, stdate2 As Date
Dim colCount, colCount1 As Integer
Set ws1 = Worksheets(1)
dur = ws1.Range("C8").Value
stdate = ws1.Range("C6").Value
'Tab Resource
Set ws2 = Worksheets(2)
ws1.Range("B12:B31").Copy
ws2.Range("B5").PasteSpecial Paste:=xlPasteAll, Transpose:=False
Application.CutCopyMode = False
'Tab Effort
Set ws3 = Worksheets(3)
Set table3 = ws3.ListObjects("EffortResources")
With table3
For i = 1 To dur
.ListColumns.Add
colCount = .ListColumns.Count
.ListColumns(colCount).Range(1).Select
Selection.NumberFormat = "mmm\-yyyy"
Selection.Value = DateAdd("m", i - 1, stdate)
Next i
End With
ws1.Range("B12:B31").Copy
ws3.Range("B5").PasteSpecial Paste:=xlPasteAll, Transpose:=False
Application.CutCopyMode = False
ws3.Columns("B:BZ").AutoFit
'Tab Other Costs
Set ws1 = Worksheets(1)
dur2 = ws1.Range("C8").Value
stdate2 = ws1.Range("C6").Value
Set ws4 = Worksheets(4)
Set table4 = ws4.ListObjects("Costs")
With table4
For j = 1 To dur2
.ListColumns.Add
colCount1 = .ListColumns.Count
.ListColumns(colCount1).Range(1).Select
Selection.NumberFormat = "mmm\-yyyy"
Selection.Value = DateAdd("m", j - 1, stdate2)
Next j
End With
End Sub
Thanks in advance for the help,
A.