我正在尝试创建一个宏来对行进行分组并汇总它们在列中的项的数量,我做到了,以便可以正常工作,但是经过几行后,它就会崩溃并显示
错误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] 删除。
我来说两句