+ Reply to Thread
Results 1 to 5 of 5

VBA code not working on Mac machine running Excel 2011 (works fine on Windows!)

  1. #1
    Registered User
    Join Date
    08-19-2016
    Location
    North Carolina, USA
    MS-Off Ver
    2016
    Posts
    3

    VBA code not working on Mac machine running Excel 2011 (works fine on Windows!)

    Greetings, all,

    Can anyone see a reason why the following code---which executes precisely as expected on a Windows machine---fails to execute on a Mac (the Mac user is running Excel 2011):

    Private Sub worksheet_change(ByVal target As Range)
    Application.EnableEvents = False
    If Not Intersect(target, Me.Range("eraserange")) Is Nothing Then
    Me.Range("b10") = Me.Range("b5")
    End If
    Application.EnableEvents = True
    End Sub

    A little more detail:
    • it's a one-sheet Excel file I created in Excel 2016, Windows 10 machine, .xlsm extension, and emailed to the Mac user;
    • the Mac user is familiar with enabling macros on Excel files; indeed, I've emailed him plenty of Excel files before (created on my machine, just as described above), which contain macros that fire upon the mouse-clicking of an object on a sheet---and those work fine for him.
    • "eraserange" is just a rectangular, contiguous array of cells on that sheet of which cell B5 is a member.
    • the user is instructed to enter something in B5, and whatever is entered SHOULD auto-populate into cell B10.

    On various Windows machines it works fine; on the Mac it didn't. And as mentioned, that same Mac guy runs other macros in Excel files I send him without a hitch; the only difference is that they've always been ones which execute with a mouse-click on something, whereas this problem one is a Worksheet Change trigger.

    I really appreciate anyone's insight into what the bug-a-boo is here. Been chasing this thing around for two days now. Thanks!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code not working on Mac machine running Excel 2011 (works fine on Windows!)

    Is his Application.EnableEvents already disabled? If yes, the Change event wont trigger.

    That could have happen if the first time he tested it, maybe he had a minor issue and only got part way through the code and left the Events disabled. Then maybe he fixed the issue but didn't re-enable the events. Just a guess.

    Can you verify that the Change event is triggering?
    If yes, then verify if the IF Intersect statement is returning True or False.
    Last edited by AlphaFrog; 08-19-2016 at 06:23 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-19-2016
    Location
    North Carolina, USA
    MS-Off Ver
    2016
    Posts
    3

    Re: VBA code not working on Mac machine running Excel 2011 (works fine on Windows!)

    Hey, many thanks, AF! Sounds like a nice conjecture.

    I'll be able to run some tests with him over the weekend; he's out of his office for the evening.

    Here's where I give away my raw noobee status w.r.t. VBA: How would I go about ♦ verifying that the Change event is triggering? and then ♦ verifying whether the If (Intersect) function was returning T or F?

    I suppose re the latter I could insert a line of code to have a message box open up if the IF was returning True?

    Sincere thanks for your feedback!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code not working on Mac machine running Excel 2011 (works fine on Windows!)

    You could use a message box for both cases. The more common practice is just to use breakpoints.

    Debugging VBA Code

    Debugging VBA Code: Adding Breakpoints

    Video: Excel VBA Tutorial - Stepping and Breakpoints

  5. #5
    Registered User
    Join Date
    08-19-2016
    Location
    North Carolina, USA
    MS-Off Ver
    2016
    Posts
    3

    Wink Re: VBA code not working on Mac machine running Excel 2011 (works fine on Windows!)

    Greatly appreciated, AF; I'll have a good look at those linked resources.

    More generally, I need to spend a little time wrapping up a better understanding of this whole "Events" thing. I kinda sorta get the recommendations (received from other sources) for the
    "application.enableevents" = false, = true code lines bookends. I'm guessing it doesn't disable the code from actually performing the "Me.Range("b10") = Me.Range("b5")" line,
    it just temporarily keeps Excel from treating it as an "event" which would possibly trigger further Worksheet_Change execution.

    Interestingly, when I was testing this code on my own machine, I couldn't get the "Debug > Step Into" to operate. I use the Step Into and Run To Cursor features frequently in composing other Subs, so I'm familiar
    with their basic operation. But whenever I try to "step into" those seven little lines of Worksheet_Change code, nothing happens.

    Just gotta spend a little more quality quiet time with just me, Walkenbach's book, and the VBE Haven't been on the learning curve long enough yet.

    Really do appreciate your insights on this one, AF! When the Mac user is back in front of his machine maybe I can fire up a screen-sharing session and see what's going on inside of his box.

    Cheers!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA code Error after changed to windows 7, working fine in windows XP before
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-11-2014, 06:23 AM
  2. Code works in Windows excel 2003 and 2010 but crashes in Mac excel 2011
    By kiweed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2012, 08:46 PM
  3. Getting this code to work on MAC (ERROR 68) - works fine on Windows
    By LT1511 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2012, 11:09 PM
  4. Replies: 0
    Last Post: 03-19-2012, 07:32 PM
  5. Macros working fine on Windows Excel, but not on Mac (Excel 2011)
    By mcstenger85 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-08-2012, 08:52 AM
  6. Macros working fine on Windows (Excel 2010), but not on Mac (Excel 2011)
    By six6to8eight in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-29-2012, 11:12 PM
  7. VBA code works in Mac 2011, not Windows 2007?
    By Jedouard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2010, 01:40 PM

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