"Runtime Error '6': Overflow" When running this VBA?

webtft

New Member
Joined
Jul 2, 2012
Messages
5
Hello,
alvinwlh sent me this VBA which is the solution to this other thread:
http://www.mrexcel.com/forum/showth...s-with-Parts&p=3196643&viewfull=1#post3196643

The code is as follows:
Rich (BB code):
<code><code>Sub arrangeA_B()
Dim last_row As Integer
Dim my_range As Range
Dim rag, c As Range
Dim temp
    
    last_row = Range("B" & Rows.count).End(xlUp).Row
    For x = 1 To last_row
        Set c = Range("A:A").Find(Range("B" & x).Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not c Is Nothing Then
            If c.Row <> x And Range("B" & x).Value <> "" Then
                If c.Offset(0, 1).Value = Range("B" & x).Value Then
                    R = MsgBox("Duplication " & Range("B" & x).Value, vbOKOnly)
                    Exit Sub
                End If
                    
                temp = c.Offset(0, 1).Value
                Temp2 = c.offset(0,2).value
                c.Offset(0, 1).Value = Range("B" & x).Value
                c.Offset(0,2).Value = Range("C" & x).Value
                Range("B" & x).Value = temp
                Range("C" & x).Value = temp2
                x = x - 1
            End If
        Else
            Range("B" & Range("B" & Rows.count).End(xlUp).Row + 1).Value = Range("B" & x).Value
            Range("C" & Range("C" & Rows.count).End(xlUp).Row + 1).Value = Range("C" & x).Value
            Range("B" & x).ClearContents
            Range("C" & x).clearcontents
        End If
    Next
    
End Sub  
</code></code>

When I run it I get "Runtime Error '6': Overflow". Is there anyone who might know why this is happening? Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Maybe try changing
Code:
Dim last_row As Integer

to
Code:
Dim last_row As Long
 
Upvote 0
You may simply need to change this:
Rich (BB code):
Dim last_row As Integer
to this:
Rich (BB code):
Dim last_row As Long
 
Upvote 0
Thank you! The script runs now, but so far it's been running for about 2hrs on a list of about 10k items and claims to be "Not Responding"... Perhaps it's not working?
When it was just sorting A&B it usually took under 5 minutes in Excel 2010.
 
Upvote 0

Forum statistics

Threads
1,214,419
Messages
6,119,389
Members
448,891
Latest member
tpierce

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