Run-time error '13' Type mismatch

micfoste

New Member
Joined
Jul 17, 2008
Messages
19
I'm new to VBA and am running some code but getting a runtime error for the following, can anybody help.

Option Explicit
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 14/07/2010 by mfoster
'
Dim ws As Worksheets

For Each ws In Worksheets
Range("A1:C16").Select
Selection.AutoFormat Format:=xlRangeAutoFormatSimple, Number:=True, Font _
:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
Range("A1:C15").Select
Charts.Add

ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=ws.Range("A1:C15"), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:=ws.Name '"2002"
Next
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You have declared ws incorrectly (it is WORKSHEET not WORKSHEETS).

By the way, when looping through sheets, you either need to activate them or include the ws reference in your range reference to make it work properly. Otherwise, you will never move off the current worksheet, i.e.

Code:
Dim ws As Worksheet

For Each ws In Worksheets
    ws.Activate
...
Next ws
 
Upvote 0
You have declared ws incorrectly (it is WORKSHEET not WORKSHEETS).

By the way, when looping through sheets, you either need to activate them or include the ws reference in your range reference to make it work properly. Otherwise, you will never move off the current worksheet, i.e.

Code:
Dim ws As Worksheet
 
For Each ws In Worksheets
    ws.Activate
...
Next ws


Tks for your help
 
Upvote 0

Forum statistics

Threads
1,215,376
Messages
6,124,593
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top