For each next choking.

  • Thread starter Thread starter Jim Chandler
  • Start date Start date
J

Jim Chandler

Greetings,

Here is my problem I have code similar to the following

Dim theSheet as WorkSheet

For each theSheet in thisWorkBook
Do some code...
next theSheet

It runs the first iteration fine, but the second iteration
gives me a runtime error "type mismatch".

What I have discovered, is the second sheet is a chart.
I've moved the chart and the choke time changes, so I know
that is an issue with the chart. But I need to know what
I can do to correct this. Any help in pointing me in the
right direction would be greatly appreciated. And anyone
who just plain gives me the right answer I'll name my
first born after ;-).

Thanks,
Jim
 
Hi
one way:
Dim theSheet as WorkSheet

For each theSheet in thisWorkBook.worksheets
Do some code...
next theSheet
 
Try this

Dim theSheet As Worksheet
For Each theSheet In ThisWorkbook.Worksheets
'Do some code...
Next theSheet
 
Here is the code in it's entirety. I just copied and
pasted it so I hope you can read it.

Public Sub ComputeRollups()
Dim theSheet As Worksheet
Dim sum As Integer, numSummed As Integer
Dim theRow As Integer, theCol As Integer
Dim temp As String
For Each theSheet In ThisWorkbook.Sheets
If (theSheet.Name <> "survey tracking" And
theSheet.Name <> "Chart1" And theSheet.Name <> "CIO sector
response" And theSheet.Name <> "Yellow & Red Metrics") Then
For theRow = 5 To 36
sum = 0
If theRow = 10 Or theRow = 16 Or theRow =
21 Or theRow = 27 Or theRow = 32 Then
'skip row
Else
theCol = 4
sum = 0
Count = 0
Do While UCase$(theSheet.Cells(2,
theCol - 1).Value) <> "ROLL-UP VALUE"
If UCase$(theSheet.Cells(1,
theCol - 1).Value) <> "HQ Average" Then
temp = theSheet.Cells(2,
theCol - 1).Value
If theSheet.Cells(theRow,
theCol).Value > 0 Then
sum = sum + theSheet.Cells
(theRow, theCol).Value
Count = Count + 1
End If
End If
theCol = theCol + 2
Loop
theSheet.Cells(theRow, theCol -
1).Value = CDbl(sum) / Count
End If
Next theRow
End If
Next theSheet
End Sub
-----Original Message-----
Hi Jim

Show your other code Jim that is in this sub

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)




"Jim Chandler" <[email protected]> wrote in
message news:[email protected]...
 
Well - I figured out the difference of what I had and what
you posted. It's Worksheets, not Sheets. Thanks for
putting up with my synaptic overload.

Jim
-----Original Message-----
Hi Jim

Show your other code Jim that is in this sub

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)




"Jim Chandler" <[email protected]> wrote in
message news:[email protected]...
 
Back
Top