Mac VBA Issue

danbrawl93

New Member
Joined
Dec 15, 2016
Messages
17
Hey guys,

I have an issue transferring this code from Windows VBA (where it works) to Mac. Both are Excel 2016.

Code:
[B]Dim x As Long

[/B][B]x = [/B][I]Worksheetfunction.Sum(Range(Cells(2,3),Cells(y,6)))[/I][B][B][I][I]
[B]If x <> Range("F3").value Then
[/B][/I][/I][/B][/B][I]MsgBox "Hello"[/I][B][B][I][I][B][I]
[B]End If[/B][/I][/B][/I][/I][/B][/B]

So, on Windows "x" = Range("F3").value and so the message is not displayed. But on Mac, "x" <> Range("F3").value and the message is displayed. However, the following code does work on Mac and the message is not displayed...

Code:
(Do not declare the dimension of x)[B]

x = [/B][I]Worksheetfunction.Sum(Range(Cells(2,3),Cells(y,6)))[/I][B][B][I][I] 
[B]If x <> Range("F3").value Then 
[/B][/I][/I][/B][/B][I]MsgBox "Hello"[/I][B][B][I][I][B][I] 
[B]End If
[/B][/I][/B][/I][/I][/B][/B]
OR...

[B][I]If [/I][/B][I]Worksheetfunction.Sum(Range(Cells(2,3),Cells(y,6)))[/I][B][I] <> Range("F3").value Then 
[/I][/B][I]MsgBox "Hello"
[/I][B][B][B][B][I]End If[/I][/B][/B][/B][/B]

Please can somebody explain the issue and help! I can only assume it has something to do with declaring "x" as long. Thanks x
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
The value of y can vary, but the calculation always works out correctly - hence why the message is not displayed (as expected) when the variable "x" is not used (see the last example in my second section of code).
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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