Please help me with run-time error '6' Overflow.

S

sidd.das

Hi,
I am getting an overflow error. Below is the code. Please help me
with the fix. I am actually comparing data of two sheets and printing
Matched/Not Matched in the third sheet.

Sub compare()

Dim j As Integer, k As Integer

Set rngSheet_res = ThisWorkbook.Sheets("Compare").Range("A2:BL1000")

For j = 2 To 1000
For k = 1 To 100
If ThisWorkbook.Sheets("RC").Cells(j, k).Value =
ThisWorkbook.Sheets("FM").Cells(j, k).Value Then
ThisWorkbook.Sheets("Compare").Cells(j, k).Value = "Matched"
Else
ThisWorkbook.Sheets("Compare").Cells(j, k).Value = "Not
Matched"
End If
Next k
Next j
End Sub

After i run this i get an overflow run-time error. When i try to denug
this, it seems that there is an overflow in the loop for j.

Thanks
~sidd
 
H

Harald Staff

Hi Sidd

Your code works fine here. But don't use Integer, they are nothing but that
kind of problems. Replace Integer with Long, code will be better and
slightly faster.

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top