Error 13 Type Mismatch and Error 2023 on cell

Harry___

New Member
Joined
Jul 6, 2018
Messages
1
Hi, I am trying to make a macro that groups up rows and sums the amount of items that they have on a column, I made it so it works but after a few rows it just crashes and displays Error 13: Type mismatch.
When I open the code it highlights this line

stringb = Cells(cont2, 7)

The code is this one:
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
I can't come up with a solution and I came here to see if someone could help me, thanks in advance.


If it's necessary I can send the excel file too.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Welcome to the Board!

I suspect some bad data in there that is causing your problems.
I recommended stepping through your code line-by-line (using the F8 key in the VB Editor), and seeing with line is returning the error, and what the values of your variables are at that point.
You can then look at your data and see what the data looks like, and hopefully the error will become evident (maybe you are trying to do something like put text in a numeric variable).
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top