Consulting

Results 1 to 5 of 5

Thread: Code That Works on PC but not Mac

  1. #1

    Code That Works on PC but not Mac

    Hi folks,

    First, sorry that this code isn't posted correctly. I couldn't find the VBA button mentioned in the FAQ, and clicking the # button added a whole bunch of font gobbledygook.

    Here's an excerpt from a function that works fine on the PC. It gets hung up at wksSheet.Activate on the Mac. The error message is that the item with the specified name wasn't found.

    Any help appreciated.

    Thanks,
    Paul


    VB:
    Public Function bFivetoThree() As Boolean


    Const szSource As String = "bFivetoThree()"

    Dim wksSheet As Excel.Worksheet

    For Each wksSheet In ThisWorkbook.Worksheets

    wksSheet.Activate
    ActiveSheet.ChartObjects("DashboardCash").Activate
    ActiveChart.PlotArea.Select
    ActiveChart.SetSourceData Source:=Sheets("Data").Range("D$91:$AM$92")

    End If
    End If

    Next wksSheet

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    1. A function is really for returning values, not doing things, so suggest changing it to a sub.
    2. Try not selecting/activating at all:
    For Each wksSheet In ThisWorkbook.Worksheets
      wksSheet.ChartObjects("DashboardCash").Chart.SetSourceData Source:=Sheets("Data").Range("D$91:$AM$92")
    Next wksSheet
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thanks.

    Yes, forgive my poor choice of words, should have said sub.

    Your code is much more elegant, thanks. Still doesn't work, though, same error message.


    Quote Originally Posted by p45cal View Post
    1. A function is really for returning values, not doing things, so suggest changing it to a sub.
    2. Try not selecting/activating at all:
    For Each wksSheet In ThisWorkbook.Worksheets
      wksSheet.ChartObjects("DashboardCash").Chart.SetSourceData Source:=Sheets("Data").Range("D$91:$AM$92")
    Next wksSheet

  4. #4
    i can not test with a mac, but try using the sheet index, rather than an each object, like

    For Each ws = 1 to  ThisWorkbook.Worksheets.count
        ThisWorkbook.Worksheets(ws).ChartObjects("DashboardCash").Chart.SetSourceData Source:=Sheets("Data").Range("D$91:$AM$92") 
    Next ws
    though it seems strange to have the same chart on every sheet in the workbook

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Any sheet protected ? any sheet invisible ?

Posting Permissions

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