【问题标题】:Conversion from type 'Range' to type 'String' is not valid从“范围”类型到“字符串”类型的转换无效
【发布时间】:2015-05-28 11:14:11
【问题描述】:
    Dim i As Integer
    For i = int_start To 1 Step -1
        If InStr(rng_delete.Cells(i), "VALUE") > 0 Then
            rng_delete.Cells(i).EntireRow.Delete()
        End If
    Next i

Microsoft.VisualBasic.dll 中出现“System.InvalidCastException”类型的未处理异常。
附加信息:从“范围”类型到“字符串”类型的转换无效。

【问题讨论】:

  • 这不是 VBA,是吗?错误提示,这更像是 VB.Net。
  • 如果 rng_delete 是 Range 类型的错误消息,您应该在 if 语句中使用 rng_delete.Cells(i).Value.ToString()

标签: vb.net excel


【解决方案1】:

您需要指定要传递给 InStr 的单元格的哪个属性(通常是 .Value 或 .Text)。

If InStr(rng_delete.Cells(i).Text, "VALUE") > 0 Then

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-30
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 2018-06-14
    相关资源
    最近更新 更多