Solved

VBA - Editing Header on "Chart" Worksheet

Posted on 2010-09-01
4
913 Views
Last Modified: 2012-06-27
Experts,

I have a sub that clears the center header box and then puts in text along with some date variables. This is working fine, on the worksheets (SumOfActivity and SalesActivityQuery) within my workbook, however I have a “Chart Sheet”, thus calling it such as:

Set WS = ChartOfActivities
      WS.PageSetup.CenterHeader = “”
      WS.PageSetup.CenterHeader = “&B&14&””MONTHLY SUMMARY”… etc.

Results in Error 13 – Type Mismatch

How can I call the “Chart Sheet”? Do I need to DIM this differently then:

Dim WS As Worksheet

I tired Dim CH As Chart, or the Chart name itself.

Code and screen shot below.

Thank you in advance,
Kevin

Private Sub UpdateHeaderDataVariable()

    Application.ScreenUpdating = False
    Dim WS As Worksheet, sTmp As String
    
    Set WS = SumOfActivity
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""MONTHLY ACTIVITY" & vbCr & "Count of ALL" & vbCr & "From " & Format(dtIN1, "MM/DD/YYYY") & " to " & Format(dtIn2, "MM/DD/YYYY")
             
   Set WS = ChartOfActivities
       WS.PageSetup.CenterHeader = ""
       WS.PageSetup.CenterHeader = "&B&14&""Arial""New Business - " & Format(dtIN1, "MMMM YYYY")
    
    Set WS = SalesActivityQuery
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""Monthly Chart" & vbCr & "From " & Format(dtIN1, "MM/DD/YYYY") & " to " & Format(dtIn2, "MM/DD/YYYY")

End Sub

Open in new window

EE-Chart-Header-VBA-ERROR.jpg
0
Comment
Question by:redrumkev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 33581670
Does this work?

Dim ws as Object
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33581676
You can't declare WS as worksheet, because that will only allow Worksheets. If you wish to re-use the WS variable, you will need to declare it as "Object", or declare another variable for your chart sheets.

FWIW, this works fine for me...

    Dim ch As Chart
    Set ch = Sheets("Chart1")
    With ch.PageSetup
        .CenterHeader = "HEADER"
    End With

Also, if you are using the code name, do you need to declare a variable for it at all?

Wayne
0
 
LVL 23

Author Comment

by:redrumkev
ID: 33582512
Wayne,

The following worked perfectly, THANK YOU!

Kevin

Private Sub UpdateHeaderDataVariable()

    Application.ScreenUpdating = False
    Dim WS As Worksheet, CH As Object, sTmp As String
    
    Set WS = SumOfActivity
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""FIRST HEADER"
             
    Set CH = ChartOfActivities
        CH.PageSetup.CenterHeader = ""
        CH.PageSetup.CenterHeader = "&B&14&""Arial""CHART HEADER"
    
    Set WS = SalesActivityQuery
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""HEADER SALES"

End Sub

Open in new window

0
 
LVL 23

Author Closing Comment

by:redrumkev
ID: 33582517
Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question