Seems to work ... now
Your replicate had a number if things that were not updated
Other suggestions included
(You could have avoided the issue by modularizing and having one sub with the table logic and just calling it with the right parameters for each use)
Option Explicit ' I like to use this, others may not
'personal style, but I like to keep event handlers small and call a standard module
Private Sub InitializeProject_Click()
Call InitProject
End Sub
Option Explicit ' I like to use this, others may not
Sub InitProject()
' Dim ws1 without the 'As Worksheet' assumes Variant type. I like to specifically Type variables, others may not
Dim ws1 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
Dim dur As Variant, dur2 As Variant
Dim i As Long, j As Long
Dim table3 As ListObject, table4 As ListObject
Dim stdate As Date, stdate2 As Date
Dim colCount As Integer, colCount1 As Integer
Set ws1 = Worksheets("Project Data") ' used ws name not index
dur = ws1.Range("C8").Value
stdate = ws1.Range("C6").Value
'Tab Effort
Set ws3 = Worksheets("Effort") ' used ws name not index
Set table3 = ws3.ListObjects("EffortResources")
With table3
For i = 1 To dur
.ListColumns.Add
colCount = .ListColumns.Count
.DataBodyRange.Columns(colCount).NumberFormat = "mmm\-yyyy"
.DataBodyRange.Columns(colCount).Value = DateAdd("m", i - 1, stdate)
Next i
End With
'Tab Other Costs
Set ws4 = Worksheets("Other Costs") ' used ws name not index
Set table4 = ws4.ListObjects("Costs")
With table4
For j = 1 To dur
.ListColumns.Add
colCount1 = .ListColumns.Count 'you used colCount1 here, but not below
.DataBodyRange.Columns(colCount1).NumberFormat = "mmm\-yyyy"
.DataBodyRange.Columns(colCount1).Value = DateAdd("m", j - 1, stdate) ' i or j ??? j seems to work better
Next j
End With
End Sub