PDA

View Full Version : Code That Works on PC but not Mac



throtmorton
09-15-2014, 07:23 AM
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

p45cal
09-15-2014, 09:25 AM
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

throtmorton
09-15-2014, 10:43 AM
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.



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

westconn1
09-16-2014, 05:46 AM
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

snb
09-16-2014, 08:08 AM
Any sheet protected ? any sheet invisible ?