I am getting A subscript out of range error when I change a cell column reference from a 2 to a 9. It is actually anything greater than 4 will set it off. Can anyone see the issue?
Private Sub Workbook_Open()
c = Sheets.Count
For Z = 1 To c
If Sheets(Z).Name = "Sheet1" Then GoTo line1
If Sheets(Z).Name = "dat" Then GoTo line1
Sheets(Z).Select
a = Application.WorksheetFunction.CountA(Columns(1))
b = Application.WorksheetFunction.CountA(Columns(2))
If a - b < 1 Then GoTo line1
ReDim q(a - b) As Integer
inc = 0
For x = 2 To a
If Cells(x, 9) = "" Then q(inc) = Cells(x, 1): inc = inc + 1
'error at above line
Next x
Sheets("dat").Select
v = Application.WorksheetFunction.CountA(Columns(1))
For y = 1 To inc
Cells(v + y, 1) = q(y - 1)
Cells(v + y, 2) = Sheets(Z).Name
Next y
line1: 'jump out
Next Z
Sheets("dat").Select
v = Application.WorksheetFunction.CountA(Columns(1))
For x = 1 To v
Cells(x, 3) = Cells(x, 2) & ", " & Cells(x, 1)
Next x
End Sub
Private Sub Workbook_Open()
c = Sheets.Count
For Z = 1 To c
If Sheets(Z).Name = "Sheet1" Then GoTo line1
If Sheets(Z).Name = "dat" Then GoTo line1
Sheets(Z).Select
a = Application.WorksheetFunction.CountA(Columns(1))
b = Application.WorksheetFunction.CountA(Columns(2))
If a - b < 1 Then GoTo line1
ReDim q(a - b) As Integer
inc = 0
For x = 2 To a
If Cells(x, 9) = "" Then q(inc) = Cells(x, 1): inc = inc + 1
'error at above line
Next x
Sheets("dat").Select
v = Application.WorksheetFunction.CountA(Columns(1))
For y = 1 To inc
Cells(v + y, 1) = q(y - 1)
Cells(v + y, 2) = Sheets(Z).Name
Next y
line1: 'jump out
Next Z
Sheets("dat").Select
v = Application.WorksheetFunction.CountA(Columns(1))
For x = 1 To v
Cells(x, 3) = Cells(x, 2) & ", " & Cells(x, 1)
Next x
End Sub