Dear Gurus,
I'm having troubles in replicating a set of code in the same Sub.
Basically (with the support of this forum) I've been able to complete a code section which is entitled to add some columns to a table on the basis of a difference in months.
Now I'm trying to make the same operation on another sheet/ table and I will need to make the same at least on some other worksheets.
But, I'm getting an "Application-defined or object-defined error".
Here below the code:
Private Sub InitializeProject_Click()
Dim ws1, 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 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
'Tab Other Costs
Set ws4 = Worksheets("Other Costs")
Set table4 = ws4.ListObjects("Costs")
With table4
For j = 1 To dur
.ListColumns.Add
colCount1 = .ListColumns.Count
.ListColumns(colCount1).Range(1).Select
Selection.NumberFormat = "mmm\-yyyy"
Selection.Value = DateAdd("m", j - 1, stdate)
Next j
End With
End Sub
Could you please advise?
Thanks in advance,
A.