+ Reply to Thread
Results 1 to 5 of 5

Delete Unique Values Macro Skipping Some Values

Hybrid View

  1. #1
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Delete Unique Values Macro Skipping Some Values

    Hi,

    I have two Macros that Delete unique Values:

    Public Sub DeleteUnique()
    Dim rngData As Range
    Set rngData = Range(Cells(2, "A"), Cells(Rows.Count, "A").End(xlUp))
    With rngData.Offset(, Columns.Count - 1)
        .FormulaR1C1 = "=IF(COUNTIF(" & rngData.Address(1, 1, xlR1C1) & ",RC1)=1,""x"",0)"
        .Calculate
        On Error Resume Next
        .SpecialCells(xlCellTypeFormulas, xlTextValues).EntireRow.DELETE
        On Error GoTo 0
        .Clear
    End With
    Set rngData = Nothing
    End Sub
    and

    Sub Del_Unique()
    Application.ScreenUpdating = False
    Columns("B:B").Insert Shift:=xlToRight
    Columns("A:A").copy Destination:=Columns("B:B")
    i = Application.CountIf(Range("A:A"), "<>") + 50
    If i > 65536 Then i = 65536
    Do
    If Application.CountIf(Range("B:B"), Range("A" & i)) = 1 Then
    Rows(i).DELETE
    End If
    i = i - 1
    Loop Until i = 0
    Columns("B:B").DELETE
    Application.ScreenUpdating = False
    End Sub
    both of them give inaccurate results.

    I make sure I Round the values to 4 decimal places so my data is uniform but still these macros delete some duplicate values and I can't have that.

    Can you see where they go wrong or how they can be improved?

    Which one is the better approach?

    Thanks for any help.
    live logic & long prosper

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Delete Unique Values Macro Skipping Some Values

    Here is some sample coding that will delete rows in which column A contains unique values as displayed.
    Attached Files Attached Files
    Gary's Student

  3. #3
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Re: Delete Unique Values Macro Skipping Some Values

    Jakobshavn,

    Now there's some programming. I like your style. I'm just a hack myself. I've put together a huge stock analysis program in Excel that's too sluggish to get through stocks with lots of data. I'll need to streamline it if it's profitable. Can I keep you in mind for some extra cash when that time comes?

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Delete Unique Values Macro Skipping Some Values

    If you need help, mine is free (and a bargain at twice the price!)

  5. #5
    Forum Contributor stockgoblin42's Avatar
    Join Date
    05-26-2011
    Location
    vancouver, canada
    MS-Off Ver
    Excel 2010
    Posts
    222

    Re: Delete Unique Values Macro Skipping Some Values

    That rocks. Rowkiller works great. I'd like to try an alteration. Can you have a look at:

    http://www.excelforum.com/excel-prog...92#post3254192

+ 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