Vex Star

Vex Star

Computers and Programming

Vex Star RSS Feed
 
 
 
 

Why am I getting an Overflow error?

Case 1
Do
If x >= 23 And x < 28 Then
i = "m"
ElseIf x >= 29 And x < 35 Then
i = "s"
ElseIf x >= 35 And x < 41 Then
i = "y"
ElseIf x >= 41 And x < 47 Then
i = "AE"
ElseIf x >= 47 And x < 53 Then
i = "AK"
ElseIf x >= 53 And x < 59 Then
i = "AQ"
ElseIf x >= 59 And x < 65 Then
i = "AW"
End If

Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "19").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("F" & x).Value ‘Sunday / Holiday
Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "21").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("y" & x).Value ‘ From – Work
Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "22").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("ab" & x).Value ‘ Until – Work
Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "24").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("AK" & x).Value ‘ Break time – Work
Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "33").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("n" & x).Value ‘ From – Travel
Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "34").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("q" & x).Value ‘ Until – Travel
Workbooks("weeklyreport.xls").Sheets("Timesheet"). range(i & "35").Value = Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("v" & x).Value ‘ Break time – Travel
‘add worklist later

x = x + 1
If Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & x).EntireRow.Hidden = True Then
Do
x = x + 1 <———–overflow
Loop Until Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & x).EntireRow.Hidden = False And Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & x).Value = 1
End If
Loop Until x = 64
Workbooks("weeklyreport.xls").SaveAs "C:" & pnumber & "_" & firstname & "_" & familyname & "_" & csnumber & "_" & calendarweek & "_" & year & ".xls", FileFormat:=xlNormal

This is the code for my first case. This code is supposed to transfer data to another sheet but I keep getting an overflow error in the said location.
what language is this ?
cos this in not c nor c++

what language is this ?
cos this in not c nor c++

I’m no help but would guess this is Excel VBA…
you are using x as a counter in nested loops and you are checking for when x = 64.
When you hit your "loop until" x will always be an odd number when it checks to terminate the loop
As was already stated, your outer loop is looking for a specific value of x (64) as the terminating condition, however you are sometimes incrementing x by 2 or more (depending on the number of iterations of the inner loop).

I would suggest using two loop counters, perhaps x and y (I would use i,j for this). Test for x = 64, but in your inner loop increment y instead and use y instead of x to do whatever the hell that does (index an array?)

Simply changing the terminating condition from x > 64 to x >= 64 will likely not give the desired result, if of course you actually intend the outer loop to iterate 64 times.

like this:

x = x + 1

If Workbooks("newapproach2replaced8updatesaveex.xls") Sheets("TimesheetRich").range("BF" & x).EntireRow.Hidden = True Then
    Do
       y = y + 1
    Loop Until Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & y).EntireRow.Hidden = False And Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & y).Value = 1
End If

Loop Until x = 64

This is of course dependent on my understanding of what that hideous code is supposed to be doing… which isn’t great lol

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply