• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

[Solved]Very simple macro, Overflow error

dourpil

Member
Hi all!

Without further adue, here's the code:

Code:
Sub lalala()

Dim x As Variant, Z As Variant, w As Variant
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
For y = 15 To 17

x = ws.Cells(3, y) + ws.Cells(2, y)
Z = 100 * ws.Cells(3, y)
w = Z / x
ws.Cells(4, y) = w
Next y
Next ws

End Sub

The Overflow error occurs when it reaches the 4th worksheet. The yellowed line is the "w = Z / x" one. The values there would be Z = 4700 and x = 9305.
Nothing to overflow about, theoretically !

By the way, when I don't loop through worksheets and only run my code for the cell at which it gives me an error, it works.

Any idea?

(Edit: I know variant isn't a great variable type here, I was going with Long or double but everything gives an error)

(Edit2: I did some more testing and for some reason my Z and x both are considered as 0. It explains why the overflow, but I still don't know why the values are suddenly not taken into account)


(Edit3: I'm the dumbest person there is. I had a hidden worksheet. With zeros on.)
 
Last edited:
Thanx for updating the post with your solution
That would have been very difficult to diagnose without a sample file!
 
Back
Top