VBA: Compile Error when run on mac

chris3131

New Member
Joined
May 19, 2015
Messages
9
When I run the following code on a PC (Excel 2013) it works fine. When I run it on a Mac I get a Compile Error (Expected Function or Variable) at the line:
"With ActiveCell.SpecialCells(xlLastCell).Select"

Code:
Sub import_reccurring_transactions()

    Application.ScreenUpdating = False
    
' name workbook & worksheet
    ActiveWB1 = ActiveWorkbook.Name
    ActiveWS1 = ActiveSheet.Name

' filter data for relevant month
    Range("G3").Select
    select_month1 = ActiveCell.Value
    select_month2 = Mid(select_month1, 4, 2)
    If select_month2 = "" Then Exit Sub

    Sheets("Recurring Transactions").Select
        If select_month2 = "01" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodJanuary, Operator:=xlFilterDynamic
        ElseIf select_month2 = "02" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodFebruray, Operator:=xlFilterDynamic
        ElseIf select_month2 = "03" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodMarch, Operator:=xlFilterDynamic
        ElseIf select_month2 = "04" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodApril, Operator:=xlFilterDynamic
        ElseIf select_month2 = "05" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodMay, Operator:=xlFilterDynamic
        ElseIf select_month2 = "06" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodJune, Operator:=xlFilterDynamic
        ElseIf select_month2 = "07" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodJuly, Operator:=xlFilterDynamic
        ElseIf select_month2 = "08" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodAugust, Operator:=xlFilterDynamic
        ElseIf select_month2 = "09" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodSeptember, Operator:=xlFilterDynamic
        ElseIf select_month2 = "10" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodOctober, Operator:=xlFilterDynamic
        ElseIf select_month2 = "11" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodNovember, Operator:=xlFilterDynamic
        ElseIf select_month2 = "12" Then
            ActiveSheet.Range("$J$7:$W$1200").AutoFilter Field:=1, Criteria1:=xlFilterAllDatesInPeriodDecember, Operator:=xlFilterDynamic
        End If

'copy/paste data into new workbook
    ActiveSheet.AutoFilter.Range.Copy
    Workbooks.Add.Worksheets(1).Select
    ActiveWB2 = ActiveWorkbook.Name
        Selection.PasteSpecial Paste:=xlPasteValues

' check to see if there are any recurring transactions for this month
    With ActiveCell.SpecialCells(xlLastCell).Select
        LastRow = Selection.Row
        If (LastRow = 1) Then
            ActiveWorkbook.Close False
            Windows(ActiveWB1).Activate
            ActiveSheet.ShowAllData
            Application.GoTo reference:="input_tt"
            Sheets(ActiveWS1).Activate
            Range("B10").Select
            msg2 = MsgBox("There are no recurring transactions for this month", vbInformation)
            Exit Sub
        End If
    End With
    
'remove 'blank' cells
    Call blank_cell_remover

'sort data
    ActiveCell.SpecialCells(xlLastCell).Select
    Range(Selection, Cells(1)).Select
        Selection.Sort Key1:=Range("A2"), Order1:=xlAscending

'copy/paste data back into Balance Sheet
    ActiveCell.SpecialCells(xlLastCell).Select
    ActiveCell.Offset(-1, 0).Select
    LastRow = Selection.Row
    
    Range("A1:A" & LastRow).Select
        Selection.Copy
    
    Windows(ActiveWB1).Activate
    Sheets(ActiveWS1).Activate
    
    Range("B10").Select
        If ActiveCell.Value = "" Then
            receipt_paste_start = ActiveCell.Offset(0, 3).Address
            expense_paste_start = ActiveCell.Offset(0, 12).Address
            Selection.PasteSpecial Paste:=xlPasteValues
        ElseIf ActiveCell.Offset(1, 0).Value = "" Then
            receipt_paste_start = ActiveCell.Offset(0, 3).Address
            expense_paste_start = ActiveCell.Offset(0, 12).Address
            Selection.Offset(1, 0).PasteSpecial Paste:=xlPasteValues
        Else
            Selection.End(xlDown).Offset(1, 0).Select
            receipt_paste_start = ActiveCell.Offset(0, 3).Address
            expense_paste_start = ActiveCell.Offset(0, 12).Address
            Selection.PasteSpecial Paste:=xlPasteValues
        End If
    
    Windows(ActiveWB2).Activate
    Range("C1:H" & LastRow).Select
        Selection.Copy
    Windows(ActiveWB1).Activate
    Sheets(ActiveWS1).Activate
        Range(receipt_paste_start).Select
        Selection.PasteSpecial Paste:=xlPasteValues
    
    Windows(ActiveWB2).Activate
    Range("J1:N" & LastRow).Select
        Selection.Copy
    Windows(ActiveWB1).Activate
    Sheets(ActiveWS1).Activate
        Range(expense_paste_start).Select
        Selection.PasteSpecial Paste:=xlPasteValues

'tidy
    Windows(ActiveWB2).Activate
    ActiveWorkbook.Close False
    
    Windows(ActiveWB1).Activate
    Sheets("Recurring Transactions").Activate
    ActiveSheet.ShowAllData
    
    Application.ScreenUpdating = False
    Application.GoTo reference:="input_tt"
    Application.ScreenUpdating = True
    
    Sheets(ActiveWS1).Activate
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    Range("B10").Select
    
End Sub

Is anyone able to help explain why this happens and how I can fix the problem?
Also, am I likely to experience other issues when running VBA on a Mac?

Thanks
Chris
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I'd start by removing the word With and the 'End With' line which aren't working anyway.

Depending on the Mac Office version you can expect about 85-90% compatibility at best. (Or none if it's Office 2008!)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,393
Messages
6,124,680
Members
449,180
Latest member
kfhw720

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