VBA runtime error '6': Overflow

  • [h=1]VBA runtime error '6': overflow [code here][/h]I have 2 worksheets giving me the same error. This is part of the code. What do I need to change here in order to get rid of this error? Thanks in advance!


    code 1:


    Code 2:

    Code
    Private Function SetLastRow(WorksheetName As String) As Integer
        SetLastRow = Sheets("Data Role Coverage").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
    End Function

    MODERATOR EDIT


    Welcome to OZ Grid
    Please use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window.


    I’ve added them this time but please comply in the future

  • Re: VBA runtime error '6': Overflow


    Hi, snooks679,


    instead of using Integer try using Long:

    Code
    Dim row As Long
    Dim LastRow As Long
    '...
    Private Function SetLastRow(WorksheetName As String) As Long


    Ciao,
    Holger

  • Re: VBA runtime error '6': Overflow


    Quote from HaHoBe;661030

    Hi, snooks679,


    instead of using Integer try using Long:

    Code
    Dim row As Long
    Dim LastRow As Long
    '...
    Private Function SetLastRow(WorksheetName As String) As Long


    Ciao,
    Holger



    Code


    HoIger,


    This doesn't seem to work. My original code works for fewer rows but it fails when it has 800 rows.

  • Re: VBA runtime error '6': Overflow


    It works now! I had missed a couple lines that had:

    Code

    Dim row as integer, I changed all to:

    Code

    Dim row as long and seems to work fine now.


    Holger thank you for your assistance.

  • Re: VBA runtime error '6': Overflow


    I'm having a similar issue to this and was hoping to get some assistance. I am also receiving a run-time error 6 Overflow error and can't identify what's causing this. Below is my code:



    The line RecentMonth = Workbooks(wb).Sheets("Full File July").Range(Cells(12, 1), Cells(SheetLastRow, SheetLastcolumn)).Value is what is causing the error. There are only 21 columns in the sheet so I don't think the Byte assignment should be an issue(?) Any insights would be much appreciated!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!