Solved

VBA - Editing Header on "Chart" Worksheet

Posted on 2010-09-01
4
905 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

790 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