Run time error '06 on one computer but macro works on another

cmolitor

New Member
Joined
Feb 20, 2013
Messages
2
My work uses a macro with one specific file that seems to work on every computer but mine. When I run the macro, I get the Run-time error '06 overflow message. When I use the debug option, it brings me to a part of the code that shows " x = x + 1". As I've said, this macro will work on the same file on a different computer with no errors. I have no VBA experience and I am using Excel 2010, and my security setting is set so that I can run any macro (lowest security level). The macro is below:


Code:
Sub Temp_Hours_Report()
'
' Macro1 Macro
' Macro recorded 3/25/2010 by Jason Feil
'
Dim x As Integer 'row number counter
Dim EEHours As Double
Dim TodayDate As String
TodayDate = Mid(Range("b2").Value, 14, 99)
Dim StartRow As Integer
Dim KerryDept As String
            
'Unmerge all cells
    Cells.Select
    With Selection
        .WrapText = False
        .MergeCells = False
    End With
'Add date column
    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight
    Range("D17").Select
    Columns("A:A").Delete
'Delete data rows not containing agency name
x = 1
Dim AgencyName As String 'To hold agency name used to identify agency employees
AgencyName = "Adecco"
Dim BlankRows As Integer
BlankRows = 0
'Find first row of Employee Data
    Do Until Range("B" & x).Value = "ID"
        If Range("B" & x).Value = "ID" Then
            
        Else
            x = x + 1
        End If
        
    Loop
    
    StartRow = x
    Range("C" & StartRow).Value = "Date"
    If Range("D" & x).Value = "" Then
        Range("D:D").Delete
    End If
    
'    Range("Q" & x).Value = "Hours"
'    Range("Q" & x).Interior.ColorIndex = 15
'    Range("Q" & x).HorizontalAlignment = xlRight
'    Range("Q" & x).Font.Size = 9
    x = x + 1
    
'Delete non-agency names
    Do Until BlankRows = 40
        If Left(Range("A" & x).Value, 6) = AgencyName Then 'Temp associate
            'Add hours format conversion
            EEHours = Left(Range("I" & x).Value, InStr(Range("I" & x).Value, ":") - 1) + Right(Range("I" & x).Value, 2) / 60
            
            Range("I" & x).Value = EEHours
            Range("I" & x).NumberFormat = "#,##0.00"
            Range("C" & x).Value = TodayDate
            'Add Kerry Dept column
    
            If InStr(Range("D" & x).Value, "/") = "6" Then
                KerryDept = Mid(Range("D" & x).Value, 15, 4)
            Else
                KerryDept = Mid(Range("D" & x).Value, 16, 4)
            End If
            Range("D" & x).NumberFormat = "@"
            Range("D" & x).Value = KerryDept
        
            x = x + 1
        ElseIf Range("A" & x).Value = "" Then 'blank row
            BlankRows = BlankRows + 1
            Selection.EntireRow.Delete
        Else 'Not temp associate
            Range("A" & x).Select
         Selection.EntireRow.Delete
    
        End If
        
    Loop
 
'Delete all header information
    x = 1
    Do Until Range("B" & x).Value = "ID"
    If Range("B" & x).Value = "ID" Then
    
    Else
        Range("B" & x).EntireRow.Delete
    End If
    Loop
'Delete extra columns
    Range("E:E").Delete
    Range("E:E").Delete
    Range("E:E").Delete
    Range("E:E").Delete
    Range("F:F").Delete
    Range("F:F").Delete
    
End Sub
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Is everyone using the same version of Excel? Generally row variables should be declared as "Long". Excel 2007+ allow more rows than can be represented by an "Integer". I don't see any obvious reason you would loop off the end of the sheet and they wouldn't unless the sheet is really large.
 
Upvote 0
Yes, we are all using Excel 2010. I have no experience with VBA, so I'm sorry if this question is stupid, but what are the row variables declared as right now? I dont' know if it matters, but the sheet is not that large, there is usually less than 1000 rows.
 
Upvote 0
There is a line at the top of the macro that says "Dim x as Integer 'row number counter"

But if the sheet only has 1000 rows then there is something else going on that is keeping one of the loops from terminating. Are you certain that there is an entry somewhere in column B that says "ID"?

I know you said id dies on the line that says "X = X + 1" but there are several of those. What is the line above where it stops?
 
Upvote 0
I also noticed that you do not increment X when you find a blank row but you are still checking the value in Ax. This means you are going to check the same cell 40 times and increment BlankRows each time (until BlankRows=40)
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top