469,072 Members | 1,846 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,072 developers. It's quick & easy.

I get a runtime error when trying to run a macro and I would like to know how to fix

Hi, I am getting a message that says Runtime Error '6': Overflow when I run the following code.

How do I fix this?
Expand|Select|Wrap|Line Numbers
  1. Sub GoldCustomersHealthcheck()
  2. Dim i As Integer, MessageString As String
  3.  
  4. MessageString = ""
  5.  
  6. For i = 2 To ActiveSheet.UsedRange.Rows.Count
  7.     If Range("B" & i).Value - Range("C" & i).Value > Range("MaxAbsolute").Value _
  8.         Or (Range("B" & i).Value - Range("C" & i).Value) / Range("B" & i).Value > Range("MaxPercentage").Value Then
  9.  
  10.         MessageString = MessageString & Range("A" & i).Value & ","
  11.     End If
  12. Next i
  13.  
  14. If MessageString <> "" Then
  15.     MessageString = Left(MessageString, Len(MessageString) - 2)
  16.     MsgBox ("These customers exceeded the maximum fall last week:" & vbLf & MessageString)
  17. Else
  18.     MsgBox ("No customers exceeded the maximum fall last week.")
  19. End If
  20.  
  21. End Sub
Thanx!
Oct 29 '13 #1
1 1235
MikeTheBike
637 Expert 512MB
Hi

It would be usfull if you could indicate which line throws the error, but my first guess is that the used range is more than 32k rows, in which case try dimesioning i as long.

??

MTB
Oct 30 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Jeff Thur | last post: by
2 posts views Thread by ticars | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.