我正在尝试制作一个宏,对行进行分组并对列上的项目数量进行求和,我这样做了,所以它可以工作,但在几行之后它就会崩溃并显示
Error 13: Type mismatch.
当我打开代码时,它会突出显示这一行
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
来获取字符串形式的错误文本。
关于单元格上的 VBA 宏 : Error 13 Type Mismatch, 错误 2023,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51209772/