Overflow Error

L

LeeL

Any ideas, please?

The sub below stops with Run-time error '6':
Overflow

Sub ColourIt()

NumOfRows = Cells(Rows.Count, 1).End(xlUp).Row

Dim OnHand As Integer
Dim ATS As Integer

For CurrentRow = 2 To NumOfRows

OnHand = ActiveSheet.Cells(CurrentRow, 6)
ATS = ActiveSheet.Cells(CurrentRow, 7)

If OnHand + ATS1 = 0 Then
Cells(CurrentRow, 2).Interior.ColorIndex = 22
End If

Next
End Sub
 
P

p45cal

Next time it stops, go into debug mode and hover over *CurrentRow* i
the code. It should tell you its value. Then go to your sheet and t
that row and look in column F. Is the number there greater than 32,76
or less than -32,768? I bet you it is.
Change:
Dim OnHand As Integer
to:
Dim OnHand As Long

It might do to do that for ATS too.
Note that later in the code there's a variable called ATS1 which i
always empty; a typo
 
L

LeeL

Thanks for the quick response! Long solves it!

OnHand + ATS is > 32,767 and The ATS1 is a typo

After your response found Data Type Summary

Would double be even less likly to error?

Integer 2 bytes -32,768 to 32,767
Long 4 bytes -2,147,483,648 to 2,147,483,647
Double 8 bytes -1.79769313486231E308 to -4.94065645841247E-324 for negative
values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values
 
P

p45cal

Re: > Would double be even less likly to error?Likeliness depends -entirely -on the likeliness of your data to excee
-2,147,483,648 to 2,147,483,647 (and not being a whole number!)
 

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

Similar Threads


Top