+ Reply to Thread
Results 1 to 3 of 3

Get Rid of the False Positive Results of the Code.

  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    Houston, USA
    MS-Off Ver
    Excel 2010
    Posts
    21

    Get Rid of the False Positive Results of the Code.

    To Whom It May Concern,

    I try to replace 5 cells of Row N to "Same As Above" when the values of these cells of Row N are same as those of Row N-1 respectively.

    However, I always have problem with false positive results, i.e. they are not the same, but replaced anyway.

    PHP Code: 
    Sub Test_Lease()
    '
    Test_Lease Macro
    '
    '   
    Proper all worksheet
            Dim ws 
    As Object
            Dim LCell 
    As Range
            Dim X 
    As Long
            Dim Lr 
    As Long
            X 
    ActiveSheet.UsedRange.Rows.Count
            Lr 
    Cells(Rows.Count"A").End(xlUp).Row 1
            
           
            Application
    .ScreenUpdating 0
    '   Delete unwanted columns
            Columns("B:B").Select
            Selection.Delete
            
    '   
    Move Last Prod next to First Prod
            Columns
    ("U:U").Select
            Selection
    .Cut
            Columns
    ("S:S").Select
            Selection
    .Insert Shift:=xlToRight
            
    '   Format Columns
            Columns("T:X").Select
            Selection.Style = "Comma"
            Selection.NumberFormat = "_(* #,##0.0_);_(* (#,##0.0);_(* ""-""??_);_(@_)"
            Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
            
    '   
    Ranking *** BOE Descending
        Range
    ("X2").Select
        ActiveWorkbook
    .ActiveSheet.Sort.SortFields.Clear
        ActiveWorkbook
    .ActiveSheet.Sort.SortFields.Add Key:=Range_
            
    "X2"), SortOn:=xlSortOnValuesOrder:=xlDescendingDataOption:= _
            xlSortNormal
        With ActiveWorkbook
    .ActiveSheet.Sort
            
    .SetRange Range("A2:Z" X)
            .
    Header xlNo
            
    .MatchCase False
            
    .Orientation xlTopToBottom
            
    .SortMethod xlPinYin
            
    .Apply
        End With
        ActiveWorkbook
    .ActiveSheet.Sort.SortFields.Clear
        ActiveWorkbook
    .ActiveSheet.Sort.SortFields.Add Key:=Range_
            
    "X2:X" X), SortOn:=xlSortOnValuesOrder:=xlDescendingDataOption:= _
            xlSortNormal
        ActiveWorkbook
    .ActiveSheet.Sort.SortFields.Add Key:=Range_
            
    "D2:D" X), SortOn:=xlSortOnValuesOrder:=xlAscendingDataOption:= _
            xlSortNormal
        With ActiveWorkbook
    .ActiveSheet.Sort
            
    .SetRange Range("A1:Z" X)
            .
    Header xlYes
            
    .MatchCase False
            
    .Orientation xlTopToBottom
            
    .SortMethod xlPinYin
            
    .Apply
        End With
            
    '   Replace Duplicate Lease Production
        X = ActiveSheet.UsedRange.Rows.Count
        Y = 0
        Range("T" & X, "X" & X).Select
        For n = 1 To X - 1
            For Each cell In Selection
                If cell = cell.Offset(-1, 0) Then
                    Y = Y + 1
                End If
                If Y = 5 Then
                    Selection.Value = "Same As Above"
                Y = 0
                End If
            Next
        Selection.Offset(-1, 0).Select
        Next

            Application.ScreenUpdating = True
            
            
    End Sub 
    Please refer to the code & attachment.

    The false positive will be on Row 126 & Column T-X after you run the code. Please help.

    Thanks in advance for your help.

    Best regards,

    Matt
    Attached Files Attached Files

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Get Rid of the False Positive Results of the Code.

    Very messy code but the problem lies at:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-19-2013
    Location
    Houston, USA
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Get Rid of the False Positive Results of the Code.

    Hi Millz,

    Thank you very much for the help. Problem solved. You made my day. Thanks again.

    All the best,

    Matt

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 10-30-2013, 10:49 AM
  2. VLookup that Results with False or Blank Results
    By mycon73 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-12-2013, 07:16 PM
  3. Replies: 14
    Last Post: 06-27-2012, 04:26 PM
  4. IF function returns false positive
    By AJMaine in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2009, 03:09 PM
  5. [SOLVED] Positive Results
    By [email protected] in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 05:05 PM

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