Mac上运行时错误13但不是PC

时间:2016-01-07 17:34:25

标签: macos vba

感谢所有帮助我的人。

我在PC上写了一些VBA,但我的撰稿人使用的是mac,而Mac则不起作用。我在以下代码中遇到运行时错误13:

If Range("Home_EPIC_Flag_Count").Value = 0 Then 

是调试时突出显示为黄色的

Private Sub Worksheet_Calculate()

 ' EPIC flag conditional testing macros

 If Range("Home_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("Home_EPIC_Flag").Visible = False
 Else
        Me.Shapes("Home_EPIC_Flag").Visible = True
 End If

 If Range("Rooms_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("Rooms_EPIC_Flag").Visible = False
 Else
        Me.Shapes("Rooms_EPIC_Flag").Visible = True
 End If

 If Range("Dining_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("Dining_EPIC_Flag").Visible = False
 Else
        Me.Shapes("Dining_EPIC_Flag").Visible = True
 End If

 If Range("Spa_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("Spa_EPIC_Flag").Visible = False
 Else
        Me.Shapes("Spa_EPIC_Flag").Visible = True
 End If

 If Range("Golf_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("Golf_EPIC_Flag").Visible = False
 Else
        Me.Shapes("Golf_EPIC_Flag").Visible = True
 End If

 If Range("LocalArea_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("LocalArea_EPIC_Flag").Visible = False
 Else
        Me.Shapes("LocalArea_EPIC_Flag").Visible = True
 End If

 If Range("Business_EPIC_Flag_Count").Value = 0 Then
      Me.Shapes("Business_EPIC_Flag").Visible = False
 Else
        Me.Shapes("Business_EPIC_Flag").Visible = True
 End If

1 个答案:

答案 0 :(得分:0)

稍微重构会使您的代码更易于管理(一旦修复了命名范围问题)

Private Sub Worksheet_Calculate()

    Dim arr, x As Long
    arr = Array("Home", "Rooms", "Dining", "Spa", "Golf", "LocalArea", "Business")

    For x = LBound(arr) To UBound(arr)
         Me.Shapes(arr(x) & "_EPIC_Flag").Visible = _
                (Range(arr(x) & "_EPIC_Flag_Count").Value > 0)
    Next x

End Sub