+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : Excel 2007 VBA error

Hybrid View

  1. #1
    Registered User
    Join Date
    07-07-2008
    Location
    Cambridge, UK
    Posts
    4

    Unhappy Excel 2007 VBA error

    Hello

    I hope someone can help me. I have a very simple piece of code, that works perfectly in Excel 2003, but my users have now upgraded to 2007 and the code doesn't work. I keep getting an error: Object variable not set (Error 91). But as far as I can see I have declared everything.

    The code is:
    Dim strWkNo As Integer
    Dim strColNum As Integer
    
        strWkNo = InputBox("Which week number do you want to update to?", "Update Chart")
        
        strColNum = strWkNo + 1
    
        ActiveChart.SeriesCollection(1).XValues = "='Yields - Foam'!R3C2:R3C" & strColNum & ""
        ActiveChart.SeriesCollection(1).Values = "='Yields - Foam'!R5C2:R5C" & strColNum & ""
        ActiveChart.SeriesCollection(2).XValues = "='Yields - Foam'!R3C2:R3C" & strColNum & ""
        ActiveChart.SeriesCollection(2).Values = "='Yields - Foam'!R16C2:R16C" & strColNum & ""
    The error message appears the first time I am using the variable for the activechart. Very confused , like I said it works in 2003. What do I need to do to get it working in 2007? Please help

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    The code fails because there is current no active chart.

    you can check before executing code

        If ActiveChart Is Nothing Then
            MsgBox "No chart Active", vbExclamation
        Else
            ActiveChart.SeriesCollection(1).XValues = "='Yields - Foam'!R3C2:R3C" & strColNum & ""
            ActiveChart.SeriesCollection(1).Values = "='Yields - Foam'!R5C2:R5C" & strColNum & ""
            ActiveChart.SeriesCollection(2).XValues = "='Yields - Foam'!R3C2:R3C" & strColNum & ""
            ActiveChart.SeriesCollection(2).Values = "='Yields - Foam'!R16C2:R16C" & strColNum & ""
        End If
    Do you have any other code that may cause the activechart to lose focus before reaching the code you posted?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    07-07-2008
    Location
    Cambridge, UK
    Posts
    4

    Active chart

    Thanks Andy

    The user is prompted to select the chart, because the sheet has loads of charts they need to select the chart that needs updating before they run the macro. I already have an error in place...

    The full example of the code is:
    Dim strWkNo As Integer
    Dim strColNo As Integer
    
        strWkNo = InputBox("Which week number do you want to update to?", "Update Chart")
        strColNo = strWkNo + 1
        
        On Error GoTo ErrMsg
        
        ActiveChart.SeriesCollection(1).XValues = "=Forming!R31C2:R31C" & strColNo & ""
        ActiveChart.SeriesCollection(1).Values = "=Forming!R78C2:R78C" & strColNo & ""
        ActiveChart.SeriesCollection(2).XValues = "=Forming!R31C2:R31C" & strColNo & ""
        ActiveChart.SeriesCollection(2).Values = "=Forming!R77C2:R77C" & strColNo & ""
        
        Exit Sub
        
    ErrMsg:
        MsgBox "You have not selected a chart - select the PC Forming Chart"

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481
    So how are they starting the macro?

    Your example, for me, displays a error message as expected.

    Can you post example workbook where the untrapped error is raised?

  5. #5
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Moved to correct forum
    Not all forums are the same - seek and you shall find

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1