我有这个宏(用Excel 2016 / Windows编写),它是一个非常简单的预订工具,检查资产当前是预订还是免费。根据这一点,它会在预订期限结束时或下一个预订期间将在另一个工作表中开始时写入:
Sub Schaltfläche1_Klicken()
Worksheets("Tabelle10").Activate
With Columns(4)
.Find(what:="*", after:=.Cells(1, 1), LookIn:=xlValues).Activate
End With
ActiveCell.Offset(0, -3).Select
If Selection.Value = "TODAY AM" Then
Sheets("HTML Output").Range("B3").Value = "Desk booked from this afternoon. Next availability"
ActiveCell.Offset(0, 3).Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
Selection.Copy
Sheets("HTML Output").Range("C3").PasteSpecial xlPasteValues
ActiveCell.Offset(0, 1).Select
Selection.Copy
Sheets("HTML Output").Range("D3").PasteSpecial xlPasteValues
ElseIf Selection.Value = "TODAY PM" Then
Sheets("HTML Output").Range("B3").Value = "Desk booked from this afternoon. Next availability"
ActiveCell.Offset(0, 3).Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
Selection.Copy
Sheets("HTML Output").Range("C3").PasteSpecial xlPasteValues
ActiveCell.Offset(0, 1).Select
Selection.Copy
Sheets("HTML Output").Range("D3").PasteSpecial xlPasteValues
ElseIf Selection.Value = "TOMORROW AM" Or Selection.Value = "TOMORROW PM" Or Selection.Value = "FUTURE" Then
Sheets("HTML Output").Range("B3").Value = "Desk free until (including)"
ActiveCell.Offset(-1, 1).Select
Selection.Copy
Sheets("HTML Output").Range("C3").PasteSpecial xlPasteValues
ActiveCell.Offset(0, 1).Select
Selection.Copy
Sheets("HTML Output").Range("D3").PasteSpecial xlPasteValues
End If
End Sub
这在Office 2016(Windows 10)中运行得非常好,但是当我尝试在Office 2011 for Mac或Office 2015 for Mac中运行它时,会导致编译错误:预期的函数或变量。
有人可以指出正确的方向,或者告诉我如何更改代码以使其有效吗?
提前致谢! 雅舍
答案 0 :(得分:2)
VBA Excel 2011中的错误处理不如它的Window对手那么好。
您收到该错误是因为With/End With
使用了ActiveCell.Offset(0, 1).Select
重现该错误的最佳方法是将此代码粘贴到模块中
Sub Schaltfläche1_Klicken()
With ActiveCell.Offset(0, 1).Select
End With
End Sub
注意:您和我之后没有收到该错误,因为您修改了我们测试的帖子:)