Calling a Sub inside a Sheet module on Excel for Mac 2011

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have written an Excel workbook for Windows, and am now trying to make it work on Excel for Mac 2011. Several times in my code I call subs that are inside different worksheet objects. With Windows, it works fine to call them like this:

Code:
Sub MySub

If x = 1 Then Sheet1.AnotherSub

End Sub

However, on Mac it gives me: Runtime Error '1004' - Application-defined or object-defined error

FYI -- "AnotherSub" is not a Private sub.

If I try to call a sub that is inside a regular Module in this same way, it works fine. For instance:

Code:
If x = 1 Then Module1.DifferentSub

The above works.

I tried doing it like this, but this also gave the same error.

Code:
If x = 1 Then Call Sheet1.AnotherSub

Anyone know why I am getting the error, and how I can fix it?
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Are you sure the error isn’t actually being caused by the routine you’re calling?
 
Upvote 0
Seems like you may be right. The sub that is being called is tied to a button click, and clicking the button on Windows works fine, but on Excel for Mac 2011 it gives a 400 error. I stepped through the code, and it seems to throw the error in this section of the code:

Code:
    Range("N53:S55").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.0499893185216834
        .PatternTintAndShade = 0
    End With

I think it gave the error on the ".Pattern = xlSolid" line, but it may have been the one before or after.

I tested it on Excel for Mac 2016 and it did NOT give me the error. The Sub worked perfectly, just like on Windows. Anyone know VBA on Mac well enough to know why this section of code would cause a 400 error on Excel for Mac 2011?
 
Upvote 0
Since this is technically a different question than the one I first asked, should I create a new post to ask this second question?
 
Upvote 0
Upvote 0
Are you sure that the code works on everything but Excel 2011 for Mac when the circumstances are identical?

I don't use Mac, but based on the more detailed question you posted to MS forums, the code works on Excel for Mac for Range("N55:S55") but errors later for Range("N53:S55") ...

... which suggest that it's not a Mac issue, but something about the particular run circumstances?

My first guess would be worksheet protection:

- Has the code protected the sheet in the meantime?

- Or perhaps does the second occurrence refer to a different, protected, worksheet?
 
Upvote 0
Does it help if you don't select first:

Code:
    With Range("N53:S55").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.0499893185216834
        .PatternTintAndShade = 0
    End With
 
Upvote 0
Stephen: since it works fine on Excel 365 for Windows and Mac, that makes me think there is nothing wrong with the code itself. If it were a protection issue, wouldn't it fail on ALL of the platforms? But to answer your other questions, both sections of code refer to the same worksheet, and the sheet was not being protected in between the two sections.

Rory, before I saw your reply, I ended up changing the first section of code so that the Range was N53:S55, and I deleted the second section of code, since that what was giving the error. After that, it worked fine. I can't figure out why it was doing it, but at least the problem has gone away now.

Thanks to you both for trying to help! :cool:
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top