Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Overflow error when using FOR loop

Hi Group,

In the code given below, ideally I would like to have
For k = i To 65536
but I get "Overflow" error during execution. So, I have "For k = i To
30000" Or could my code be tweaked to avoid this overflow error?
Please let me know.

Is there any way to overcome this "Overflow" error

Public Sub test1()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

Dim fname As String

i = 2
l = 2

For k = i To 30000
j = i + 1

If Range("B" & i).Value < Range("B" & j).Value Then
Range("B" & l, "Z" & i).Select
Selection.Copy
Workbooks.Add
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
"C:\" & Range("A1").Value & ".txt", FileFormat:= _
xlUnicodeText, CreateBackup:=False

ActiveWindow.Close

l = j
End If

If Range("B" & j).Value = "" Then
Exit Sub
End If

i = i + 1
Next k

End Sub

Thanks,
Kevin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Overflow error when using FOR loop

Try declaring your variables as Long instead of Integer. That might help.

" wrote:

Hi Group,

In the code given below, ideally I would like to have
For k = i To 65536
but I get "Overflow" error during execution. So, I have "For k = i To
30000" Or could my code be tweaked to avoid this overflow error?
Please let me know.

Is there any way to overcome this "Overflow" error

Public Sub test1()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

Dim fname As String

i = 2
l = 2

For k = i To 30000
j = i + 1

If Range("B" & i).Value < Range("B" & j).Value Then
Range("B" & l, "Z" & i).Select
Selection.Copy
Workbooks.Add
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
"C:\" & Range("A1").Value & ".txt", FileFormat:= _
xlUnicodeText, CreateBackup:=False

ActiveWindow.Close

l = j
End If

If Range("B" & j).Value = "" Then
Exit Sub
End If

i = i + 1
Next k

End Sub

Thanks,
Kevin

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Overflow error when using FOR loop

On Jul 28, 5:27*pm, JLGWhiz wrote:
Try declaring your variables as Long instead of Integer. *That might help.



" wrote:
Hi Group,


In the code given below, ideally I would like to have
For k = i To 65536
but I get "Overflow" error during execution. So, I have "For k = i To
30000" Or could my code be tweaked to avoid this overflow error?
Please let me know.


Is there any way to overcome this "Overflow" error


Public Sub test1()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer


Dim fname As String


i = 2
l = 2


For k = i To 30000
j = i + 1


If Range("B" & i).Value < Range("B" & j).Value Then
Range("B" & l, "Z" & i).Select
Selection.Copy
Workbooks.Add
* * Range("A1").Select
* * ActiveSheet.Paste
* * Application.CutCopyMode = False
* * Application.DisplayAlerts = False


* * ActiveWorkbook.SaveAs Filename:= _
* * * * "C:\" & Range("A1").Value & ".txt", FileFormat:= _
* * * * xlUnicodeText, CreateBackup:=False


* * ActiveWindow.Close


l = j
End If


If Range("B" & j).Value = "" Then
Exit Sub
End If


i = i + 1
Next k


End Sub


Thanks,
Kevin- Hide quoted text -


- Show quoted text -


Thank you. It worked.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overflow error, need help mkerstei[_15_] Excel Programming 3 July 14th 06 03:10 AM
Overflow Error DG Excel Discussion (Misc queries) 3 April 15th 05 05:45 PM
Overflow Error DG Excel Programming 3 April 15th 05 05:45 PM
Overflow error Jim Berglund Excel Programming 3 January 30th 05 05:57 PM
Help! Overflow Error 6 Gauthier Excel Programming 6 September 24th 04 12:57 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"