Overflow Error

kayrrah07

New Member
Joined
Jan 11, 2010
Messages
8
Hi Guys,

I'm currently having a problem with this overflow error thing. I don't know how to resolve this. Please help me find a solution. Here are my codes:

Dim counter As Integer
Dim row As Integer
Dim message, mInitial As String
message = "Populate SAPHR first."
counter = 3
row = 4
If IsEmpty(Sheets("MASTER DATA").Range("A" & counter)) Then
MsgBox message
Else

Do Until IsEmpty(Sheets("CSV DATA FIELDS").Range("B" & row))
Do Until Sheets("MASTER DATA").Range("A" & counter) = Sheets("CSV DATA FIELDS").Range("C" & row)
counter = counter + 1 (when i click debug, the program points to this one)
Loop

Sheets("MASTER DATA").Rows(counter).Columns("I").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("C").Value
Sheets("MASTER DATA").Rows(counter).Columns("K").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("L").Value
Sheets("MASTER DATA").Rows(counter).Columns("L").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("S").Value
Sheets("MASTER DATA").Rows(counter).Columns("W").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("J").Value
Sheets("MASTER DATA").Rows(counter).Columns("X").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("AD").Value
If IsEmpty(Sheets("CSV DATA FIELDS").Range("G" & row)) Then
Sheets("MASTER DATA").Rows(counter).Columns("J").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("F").Value & ", " & Sheets("CSV DATA FIELDS").Rows(row).Columns("E").Value
Else
mInitial = Sheets("CSV DATA FIELDS").Rows(row).Columns("G").Value
mInitial = Left(mInitial, 1)
Sheets("MASTER DATA").Rows(counter).Columns("J").Value = Sheets("CSV DATA FIELDS").Rows(row).Columns("F").Value & ", " & Sheets("CSV DATA FIELDS").Rows(row).Columns("E").Value & " " & mInitial & "."
End If

counter = 3
row = row + 1

Loop
End If
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try dimming your variables as LONG instead of INTEGER.

Interger can only go up to 32767
 
Upvote 0
Try dimming your variables as LONG instead of INTEGER.

Interger can only go up to 32767

I've tried that already and another error occured. "Application Defined or Object-defined error" it points to this code.

Do Until Sheets("MASTER DATA").Range("A" & counter) = Sheets("CSV DATA FIELDS").Range("C" & row)

Any idea what happen sir?
 
Upvote 0
What are the values of counter and row at the time of the error?
When you debug, you can just hover your mouse over the variables to find thier current values.
 
Upvote 0
What are the values of counter and row at the time of the error?
When you debug, you can just hover your mouse over the variables to find thier current values.

The value for counter = 65537 and row = 19. Those were the values written when i hovered on it.
 
Upvote 0
The value for counter = 65537 and row = 19. Those were the values written when i hovered on it.

Range("A" & counter)

I assume you are on Excel <2007 which means 65537 is one more than the allowed rows. In other words, it is not finding what you are looking for and running out of rows to check. You need to have a failsafe in there to say if counter > rows.count then exit loop
 
Upvote 0
Range("A" & counter)

I assume you are on Excel <2007 which means 65537 is one more than the allowed rows. In other words, it is not finding what you are looking for and running out of rows to check. You need to have a failsafe in there to say if counter > rows.count then exit loop

Where do i put the code "if counter > rows.count then exit loop<!-- / message --><!-- sig -->" Please see my codes above. I dont have idea where to put it :biggrin:
 
Upvote 0
Right between the lines that say

counter = counter + 1
put the If here
Loop


But, perhaps a better question should be...

in this line
Code:
Do Until Sheets("MASTER DATA").Range("A" & counter) = Sheets("CSV DATA FIELDS").Range("C" & row)

Why is the condition not being met allowing that counter to get to such a high number?
 
Last edited:
Upvote 0
Jonmo is correct, it is always better to look for the reason of an error rather than the error itself.
 
Upvote 0

Forum statistics

Threads
1,215,757
Messages
6,126,693
Members
449,331
Latest member
smckenzie2016

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