You are going to say "please use code tags". I don't know how, please show me. And on to the question!
I am trying to run through several sheets and pull up data from them. However, even though it shows (via msgBox to pause execution) I am on the sheet of choice, all the data calls are going to Sheet1. Here's the code:
The MsgBox a gives 0, which is the expected result in Sheet1 (I put garbage in column 1 to verify and it comes out with expected result). So why is this going to Sheet1?
I am trying to run through several sheets and pull up data from them. However, even though it shows (via msgBox to pause execution) I am on the sheet of choice, all the data calls are going to Sheet1. Here's the code:
Code:
Private Sub CommandButton1_Click()
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).Activate
Sheets(Z).Select
a = Application.WorksheetFunction.CountA(Columns(1))
MsgBox a
b = Application.WorksheetFunction.CountA(Columns(9))
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
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
Cells(v + y, 3) = Cells(v + y, 2) & ", " & Cells(v + y, 1)
Next y
line1: 'jump out
Next Z
The MsgBox a gives 0, which is the expected result in Sheet1 (I put garbage in column 1 to verify and it comes out with expected result). So why is this going to Sheet1?
Last edited by a moderator: