+ Reply to Thread
Results 1 to 3 of 3

find function with a relative range

Hybrid View

  1. #1
    Registered User
    Join Date
    03-02-2010
    Location
    milwaukee, WI
    MS-Off Ver
    Excel 2003
    Posts
    2

    find function with a relative range

    First off, I'm pretty new to coding, and the use of vba and macros. I am trying to separate and format some test data. So I have written a lengthy macro to do this. Everything work great except keep getting an error in one section of code.
    I am using the find function to search for the first failure to appear in a column (J), then i am trying to locate in what sequence of tests this failure occurred in. The sequence number can be found in the E column and spaced between 5 and 15 tests apart. (so there is no set offset from the failure to the sequence number). The first bit of code is not really important. Here is my code:

    the error is occurring at "rng.Find...." line, its states "object required"

    Any help would be greatly appreciated

    Sub failure_sequence()


    Dim lastrow As Long
    Dim rng As Range
    Dim fails As Range



    lastrow = Range("B23").End(xlDown).Row

    Set fails = Cells.Find("failed", ActiveCell, xlValues, xlPart, xlByRows, xlNext, False, False)
    If fails Is Nothing Then
    Sheets.Add.Name = "failuresequence"
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "N/A"
    Range("A1").Select
    Selection.AutoFill Destination:=Range("A1:Q1"), Type:=xlFillDefault
    Range("A1:Q1").Select
    Else
    Range("J23:J" & lastrow&).Find("failed").Select
    Selection.Offset(0, -5).Select
    Set rng = Range(Selection, Selection.Offset(-15, 0))
    rng.Find("seq", ActiveCell, xlvaues, xlPart, xlByRows, xlPrevious, False, False).Select

    Selection.EntireRow.Select
    Selection.Copy
    Sheets.Add.Name = "failuresequence"
    Range("A1").Select
    ActiveSheet.Paste
    End If


    End Sub

  2. #2
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: find function with a relative range

    Welcome to the forum. Please take a moment to read the rules and then add code tags in accordance with rule #3. Thanks.

  3. #3
    Registered User
    Join Date
    03-02-2010
    Location
    milwaukee, WI
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: find function with a relative range

    My apologies


    Sub failure_sequence()
    
    
    Dim lastrow As Long
    Dim rng As Range
    Dim fails As Range
    
    
    
    lastrow = Range("B23").End(xlDown).Row
    
    Set fails = Cells.Find("failed", ActiveCell, xlValues, xlPart, xlByRows, xlNext, False, False)
    If fails Is Nothing Then
    Sheets.Add.Name = "failuresequence"
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "N/A"
    Range("A1").Select
    Selection.AutoFill Destination:=Range("A1:Q1"), Type:=xlFillDefault
    Range("A1:Q1").Select
    Else
    Range("J23:J" & lastrow&).Find("failed").Select
    Selection.Offset(0, -5).Select
    Set rng = Range(Selection, Selection.Offset(-15, 0))
    rng.Find("seq", ActiveCell, xlvaues, xlPart, xlByRows, xlPrevious, False, False).Select
    
    Selection.EntireRow.Select
    Selection.Copy
    Sheets.Add.Name = "failuresequence"
    Range("A1").Select
    ActiveSheet.Paste
    End If
    
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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