ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Chart sheet causing error (https://www.excelbanter.com/excel-programming/438525-chart-sheet-causing-error.html)

Gustaf

Chart sheet causing error
 
Hi all,

I'm having a problem at the last line of this code:

For Each ws In Workbooks(sFile).Sheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

The problem occurs when I step into a chart sheet, which results in a type mismatch error. Why does that happen how do you handle that?

Gustaf

Bob Phillips[_4_]

Chart sheet causing error
 
You probably have ws defined as a variable of type worksheet. Either change
it to Object, or outsort the charts n the code.

HTH

Bob

"Gustaf" wrote in message
...
Hi all,

I'm having a problem at the last line of this code:

For Each ws In Workbooks(sFile).Sheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

The problem occurs when I step into a chart sheet, which results in a type
mismatch error. Why does that happen how do you handle that?

Gustaf




Gustaf

Chart sheet causing error
 
You're right. The ws variable is indeed defined as Worksheet. It's preferred, because that's how it's done in the rest of the project. However, I don't think outsorting the charts would work, because the error occurs already on the "Next" line, before returning to the top of the loop.

Gustaf

Bob Phillips wrote:
You probably have ws defined as a variable of type worksheet. Either change
it to Object, or outsort the charts n the code.

HTH

Bob

"Gustaf" wrote in message
...
Hi all,

I'm having a problem at the last line of this code:

For Each ws In Workbooks(sFile).Sheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

The problem occurs when I step into a chart sheet, which results in a type
mismatch error. Why does that happen how do you handle that?

Gustaf




Bob Phillips[_4_]

Chart sheet causing error
 
If you keep it as type worksheet, you HAVE to outsort the charts, otherwise
it will just fail as you have found.

HTH

Bob

"Gustaf" wrote in message
...
You're right. The ws variable is indeed defined as Worksheet. It's
preferred, because that's how it's done in the rest of the project.
However, I don't think outsorting the charts would work, because the error
occurs already on the "Next" line, before returning to the top of the
loop.

Gustaf

Bob Phillips wrote:
You probably have ws defined as a variable of type worksheet. Either
change it to Object, or outsort the charts n the code.

HTH

Bob

"Gustaf" wrote in message
...
Hi all,

I'm having a problem at the last line of this code:

For Each ws In Workbooks(sFile).Sheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

The problem occurs when I step into a chart sheet, which results in a
type mismatch error. Why does that happen how do you handle that?

Gustaf




Bob Phillips[_4_]

Chart sheet causing error
 
It is easily outsorted like so

Dim ws As Worksheet
For Each ws In Workbooks(sFile).Worksheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

HTH

Bob

"Gustaf" wrote in message
...
You're right. The ws variable is indeed defined as Worksheet. It's
preferred, because that's how it's done in the rest of the project.
However, I don't think outsorting the charts would work, because the error
occurs already on the "Next" line, before returning to the top of the
loop.

Gustaf

Bob Phillips wrote:
You probably have ws defined as a variable of type worksheet. Either
change it to Object, or outsort the charts n the code.

HTH

Bob

"Gustaf" wrote in message
...
Hi all,

I'm having a problem at the last line of this code:

For Each ws In Workbooks(sFile).Sheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

The problem occurs when I step into a chart sheet, which results in a
type mismatch error. Why does that happen how do you handle that?

Gustaf




Gustaf

Chart sheet causing error
 
Thank you very much! :-)

Gustaf

--
Bob Phillips wrote:
It is easily outsorted like so

Dim ws As Worksheet
For Each ws In Workbooks(sFile).Worksheets
If ... Then
cboSheet.AddItem ws.Name
End If
Next

HTH

Bob



All times are GMT +1. The time now is 02:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com