ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-time error '6' overflow (https://www.excelbanter.com/excel-programming/291310-run-time-error-6-overflow.html)

Suzy[_2_]

Run-time error '6' overflow
 
I keep getting that error when I use this code
Sub test()
Dim a As Integer
For a = 50000 To 50100
Range("J1, K28").Value = a
ActiveSheet.PrintOut
Next a
End Sub

but it has always worked perfectly when I used this
Sub test()
Dim a As Integer
For a = 20000 To 20100
Range("J1, K28").Value = a
ActiveSheet.PrintOut
Next a
End Sub

But I can't figure out which part is causing the problem

Chip Pearson

Run-time error '6' overflow
 
Suzy,

An integer can contain values between +/- 32K, and when you
attempt to store 50000 in the variable 'a', you are overflowing
the capacity of an integer. Change the variable to a Long type.
E.g.,

Dim a As Long

I



"Suzy" wrote in message
...
I keep getting that error when I use this code
Sub test()
Dim a As Integer
For a = 50000 To 50100
Range("J1, K28").Value = a
ActiveSheet.PrintOut
Next a
End Sub

but it has always worked perfectly when I used this
Sub test()
Dim a As Integer
For a = 20000 To 20100
Range("J1, K28").Value = a
ActiveSheet.PrintOut
Next a
End Sub

But I can't figure out which part is causing the problem




No Name

Run-time error '6' overflow
 
It works perfectly.
Greatly Appreciated
Suzy


-----Original Message-----
Suzy,

An integer can contain values between +/- 32K, and when

you
attempt to store 50000 in the variable 'a', you are

overflowing
the capacity of an integer. Change the variable to a

Long type.
E.g.,

Dim a As Long

I



"Suzy" wrote in

message
...
I keep getting that error when I use this code
Sub test()
Dim a As Integer
For a = 50000 To 50100
Range("J1, K28").Value = a
ActiveSheet.PrintOut
Next a
End Sub

but it has always worked perfectly when I used this
Sub test()
Dim a As Integer
For a = 20000 To 20100
Range("J1, K28").Value = a
ActiveSheet.PrintOut
Next a
End Sub

But I can't figure out which part is causing the

problem


.



All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com