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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,092
Office Version
365
Platform
Windows
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
 

micfoste

New Member
Joined
Jul 17, 2008
Messages
19
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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,971
Messages
5,508,470
Members
408,687
Latest member
KevinNTU

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top