Overflow Error

krishna334

Active Member
Joined
May 22, 2009
Messages
391
Hi All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
I have 2 sheet in my workbook – MASTER & PM Manual Override<o:p></o:p>
There are some headings in 5<SUP>th</SUP> row of PM Manual Override.<o:p></o:p>
The same heading (in different sequence) are present in MASTER tab & also there is data below these headings.<o:p></o:p>
What my code does is – copies the data under the heading of the MASTER tab to the row below the same heading in the PM Manual Override tab<o:p></o:p>
<o:p> </o:p>
The problem is that now I am getting an error – “overflow” when I run the below code. Why this happens & how do i correct it?
<o:p> </o:p>
Option Base 1<o:p></o:p>
Sub rearrange()<o:p></o:p>
Dim i, j, m, n, p As Integer<o:p></o:p>
Dim FindString As String<o:p></o:p>
Dim Rng As Range<o:p></o:p>
<o:p> </o:p>
Dim Arr(100) As String<o:p></o:p>
i = 1<o:p></o:p>
j = Sheets("PM Manual Override").UsedRange.Columns.Count<o:p></o:p>
<o:p> </o:p>
For i = 1 To j<o:p></o:p>
Arr(i) = Sheets("PM Manual Override").Cells(5, i).Value<o:p></o:p>
FindString = Arr(i)<o:p></o:p>
If Trim(FindString) <> "" Then<o:p></o:p>
With Sheets("MASTER").Cells<o:p></o:p>
Set Rng = .Find(What:=FindString, _<o:p></o:p>
After:=.Cells(.Cells.Count), _<o:p></o:p>
LookIn:=xlValues, _<o:p></o:p>
LookAt:=xlWhole, _<o:p></o:p>
SearchOrder:=xlByRows, _<o:p></o:p>
SearchDirection:=xlNext, _<o:p></o:p>
MatchCase:=False)<o:p></o:p>
If Not Rng Is Nothing Then<o:p></o:p>
Application.Goto Rng, True<o:p></o:p>
m = ActiveCell.Row<o:p></o:p>
n = Sheets("MASTER").UsedRange.Rows.Count<o:p></o:p>
p = ActiveCell.Column<o:p></o:p>
<o:p></o:p>
Range(Cells(m + 1, p), Cells(n, p)).Copy Destination:=Sheets("PM Manual Override").Cells(6, i)<o:p></o:p>
<o:p> </o:p>
Else<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
End If<o:p></o:p>
End With<o:p></o:p>
End If<o:p></o:p>
Next i<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Sheets("MASTER").Range("AO3:BL3").Copy Destination:=Sheets("PM Manual Override").Range("AD4")<o:p></o:p>
Sheets("MASTER").Range("BP5:BP" & n).Copy Destination:=Sheets("PM Manual Override").Range("A6")<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
End Sub<o:p></o:p>
 
You need to set the data type of each variable and try Long instead of Integer

Code:
Dim i As Long, j As Long, m As Long, n As Long, p As Long
 
Upvote 0
This one Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
 
Upvote 0
Are you using xl2007 or above? Change the Count to CountLarge:

Rich (BB code):
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.CountLarge), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
 
Upvote 0
The problem is that in xl2007+ the number of cells on a worksheet (non-compatibility mode) exceeds the maximum size of a Long integer variable (Cout property returns a Long integer data type). Hence you need to use the typesafe CountLarge property which can accomodate the number of cells.
 
Upvote 0

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