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"
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
"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