VBA宏:错误13类型不匹配,单元格上出现错误2023

奥古斯丁·明乔尼

我正在尝试创建一个宏来对行进行分组并汇总它们在列中的项的数量,我做到了,以便可以正常工作,但是经过几行后,它就会崩溃并显示

错误13:类型不匹配。

当我打开代码时,它突出显示了这一行

stringb = Cells(cont2, 7)

代码是这样的:

Sub Juntarfilas()
    Dim Av1 As Double
    Dim cont As Long
    Dim cont2 As Long
    Dim numcol As Integer
    Dim comp1 As Integer
    Dim check As String
    Dim string1 As String
    Dim string2 As String
    Dim stringa As String
    Dim stringb As String
    Dim Rango As Variant

    Sheets("RESULTADO").Select
    numcol = Range("E2").Column
    cont = 2
    cont2 = 3

    If IsEmpty(Range("E2").Value) = True Then
        check = 0
    Else
        check = 1
    End If

    While (check = 1)
        string1 = Cells(cont, 5)
        string2 = Cells(cont2, 5)
        stringa = Cells(cont, 7)
        stringb = Cells(cont2, 7)
        comp1 = StrComp(string1, string2)
        If (comp1 = "0") Then
            Rango = Range(Cells(cont, 7), Cells(cont2, 7))
            Av1 = Application.WorksheetFunction.Sum(Rango)
            Cells(cont, 7) = Av1
            cont = cont
            cont2 = cont2
            Rows(cont2).EntireRow.Delete
        Else
            cont = cont + 1
            cont2 = cont2 + 1
        End If

        If IsEmpty(string1) = True Then
            check = 0
        Else
            check = 1
        End If
    Wend
End Sub

我无法提出解决方案,我来这里看看是否有人可以帮助我,在此先感谢。

如果有必要,我也可以发送excel文件。

ᴇʜ

类型不匹配时在细胞中出现的错误stringb = Cells(cont2, 7)包含返回一个错误(例如式#DIV/0!#N/A!或任何其他)。

stringb = Cells(cont2, 7).Text改为使用错误文本作为字符串。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

空单元格上的类型不匹配错误?

VBA错误13类型不匹配

尝试检查单元格是否包含整数时出现运行时错误 13 类型不匹配

选择多个单元格时评估错误:运行时错误'13':类型不匹配

<Excel-VBA> 将值从单元格复制到文本框时出现“类型不匹配”错误

从合并单元格中删除时键入不匹配 13 错误 - VBA

Excel-选择多个单元格时在VBA中键入不匹配错误13

更新汇率-VBA-运行时错误13类型不匹配

Excel VBA Target.Address被修改并导致错误13类型不匹配

VBA调试打印ParamArray错误13类型不匹配值

使用VBA脚本将2个时间变量分配给2个单元格中的时间值会引发类型不匹配错误13

Excel VBA 宏类型不匹配错误

继承上的 VBA 类型不匹配(错误 13),用户来自

运行另一个微型计算机时出现错误13类型不匹配的VBA

Excel VBA将数据从一个单元格转换为行(类型不匹配错误)

VBA,Excel ODBC驱动程序-对单元格中的参数使用sql查询时,类型不匹配错误

VBA Excel“错误13:类型不匹配”

运行时错误'13':清除单元格内容时键入不匹配

运行时错误“13”:宏中的类型不匹配

将公式插入单元格时,如何清除此 ByRef 参数类型不匹配错误?

如果File =“ False” Application.GetOpenFileName错误13类型不匹配

。在SearchDirection中查找变量将导致运行时错误13类型不匹配

Access数据库运行时错误13类型不匹配

类型不匹配错误#13

键入不匹配运行时错误 13,同时对多个已删除单元格撤消 Ctrl+z

Excel VBA运行时错误类型不匹配13

Excel VBA运行时错误“ 13”:类型不匹配

无法解决 VBA 数组错误 13 类型不匹配

VBA 中的类型 13 数据不匹配错误