+ Reply to Thread
Results 1 to 4 of 4

Run Time Error '6' Overflow - Macro That Find Text and Copy Range & Replace on Other Sheet

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    Karachi
    MS-Off Ver
    Excel 2003 + Excel 2010
    Posts
    19

    Run Time Error '6' Overflow - Macro That Find Text and Copy Range & Replace on Other Sheet

    Hi Guys!

    I have a data sheet "Data Oil Urban" having more than 30,000 records in 7 columns in excel 2003. I have developed a form in the sheet named "Oil Urban" with combo boxes to filter data. all filters develop a combined 'string'. a command button runs a macro which finds the 'string' generated from filters from combo boxes from "Oil Urban" and matches with the 'string' in the sheet "Data Oil Urban" column A then copy a range of data from Sheet "Data Oil Urban" and replace on Sheet "Oil Urban" as a filter result.

    The problem is that the macro for find replace works well to the 30,000 thousand rows but it gives a "run time error '6' Overflow" for the data which comes after 30 thousand rows.

    I am attaching the code below and will be highly thankful for the resolution.

    Regards,
    Hussaini


    Private Sub CommandButton1_Click()

    Dim s As String, str1, str2, str3, str4, str5 As String
    With Worksheets("Oil Urban")

    str1 = Range("a3").Value
    str2 = Range("a4").Value
    str3 = Range("a5").Value
    str4 = Range("a6").Value

    s = str1 + str2 + str3 + str4
    .Range("A7") = s

    With Worksheets("Data Oil Urban").Columns("A")
    Dim f1 As Integer, zaman1 As String
    Para1:
    Set c = .Find(s, LookIn:=xlValues)
    If Not c Is Nothing Then
    firstaddress = c.Row
    'MsgBox "Row number of the result string is" & c.Row
    'MsgBox "Row number of the result string is" & firstaddress
    Do
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Row <> firstaddress
    Else
    MsgBox "Not found"
    GoTo Para3
    End If
    Para2:
    f1 = firstaddress
    Worksheets("Data Oil Urban").Range(.Cells(f1, 7), .Cells(f1 + 26, 6)).Copy
    End With

    ActiveSheet.Paste Destination:=Worksheets("Oil Urban").Cells(12, 3)

    Para3:

    Worksheets("Oil Urban").Cells(12, 3).Select

    End With
    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Run Time Error '6' Overflow - Macro That Find Text and Copy Range & Replace on Other S

    You had declared F1 as type Integer and assigned it to the row number. The max value for a type integer is 32667. If you triy to assign it a larger value, it will generate an error. You could declare F1 as type Long.

    Or try this cleaned up code...

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 01-17-2013 at 03:19 AM.

  3. #3
    Registered User
    Join Date
    01-17-2013
    Location
    Karachi
    MS-Off Ver
    Excel 2003 + Excel 2010
    Posts
    19

    Re: Run Time Error '6' Overflow - Macro That Find Text and Copy Range & Replace on Other S

    Thanks a lot for your great contribution this code solved my problem

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,540

    Re: Run Time Error '6' Overflow - Macro That Find Text and Copy Range & Replace on Other S

    Note that this line:

    Please Login or Register  to view this content.

    Declares s and str5 as strings and the others as variants. You need to be explicit for each variable.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1