Solved

VBA - Editing Header on "Chart" Worksheet

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

785 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