VBA - How do I fix Run-time error '6': Overflow

parkerbelt

Active Member
Joined
May 23, 2014
Messages
377
The error happens at this line:

lastrow = Cells(Rows.Count, "B").End(xlUp).Row

I suspect that it is happening because my data has 97000 something rows which is over the 65000 whatever rows that the old excel used to have.

Is there a different line of code that I should be using to find the last row in a column?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
That line of code is fine.

The variable lastrow is declared as type Integer. It should be declared as type Long to accommodate the larger row value.

Dim lastrow As Long


The max value of an Integer is 32,767

The max value of a Long is 2,147,483,647
 
Last edited:
Upvote 1
That line of code is fine.

The variable lastrow is declared as type Integer. It should be declared as type Long to accommodate the larger row value.

Dim lastrow As Long

Is that all! That was easy. I can't test it right now or I'll have to restart the program, but I'm sure you're right. Thank you!!
 
Upvote 0
That line of code is fine.

The variable lastrow is declared as type Integer. It should be declared as type Long to accommodate the larger row value.

Dim lastrow As Long


The max value of an Integer is 32,767

The max value of a Long is 2,147,483,647

Thanks for this - I had the same problem with the same piece of code!
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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