检查单元格的值时类型不匹配

时间:2020-02-29 06:06:29

标签: excel vba

我的代码碰到了

错误13:类型不匹配

无论何时我输入或更改C59中的值,C59都会包含此公式 `print(np.array([arr[2:4], arr[3:5]])) # same shape` 。我猜是因为变量不同,但不知道如何解决,非常感谢任何帮助!

print(np.array([arr[:2], arr[:3]]))
[array([[0, 1],
       [2, 3]])
 array([[0, 1],
       [2, 3],
       [4, 5]])]

1 个答案:

答案 0 :(得分:0)

在除以C57时,您需要确保0不是C59,在这种情况下,#DIV/0!将是.Value(错误)

如果单元格包含错误,则无法检查其C59属性。

首先检查单元格If IsError(Worksheets("InvPL").Range("C59")) Then Msgbox "C59 contains an error. If C57=0 then it is a divide by zero error." Else If Range("C59").Value = "0" Then Sheets("InvPL").Rows("78:79").EntireRow.Hidden = True Else Sheets("InvPL").Rows("78:79").EntireRow.Hidden = False End If End If 中的错误:

With

或更干净的版本,使用Worksheets块,并使用Sheets代替 With Worksheets("InvPL") If IsError(.Range("C59")) Then Msgbox "C59 contains an error. If C57=0 then it is a divide by zero error." Else If .Range("C59").Value = "0" Then .Rows("78:79").EntireRow.Hidden = True Else .Rows("78:79").EntireRow.Hidden = False End If End If End With ,因为工作表也可以引用图表对象:

C57

如果您还想在发生错误时隐藏/取消隐藏这些行,则可以稍微更改逻辑。


另一种选择是更改公式,当0=IF(C57=0,0,ROUNDUP(D59/C57,0)) 时返回零而不是错误:

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dp"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ProgressBar
        android:id="@+id/hamlebar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:max="100" />

    <TextView
        android:id="@+id/bartext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hamle"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        android:background="@android:color/transparent" />

</LinearLayout>