+ Reply to Thread
Results 1 to 5 of 5

Deleting Repeated Data

Hybrid View

KHaberstroh Deleting Repeated Data 05-18-2007, 09:49 AM
stevebriz Where does the new data get... 05-18-2007, 10:25 AM
mccreaso Try: Sub... 05-18-2007, 10:27 AM
mccreaso Just came across this: ... 05-18-2007, 10:29 AM
KHaberstroh MCCREASO!! That is exactly... 05-18-2007, 11:46 AM
  1. #1
    Registered User
    Join Date
    05-18-2007
    Posts
    13

    Deleting Repeated Data

    I am in need of some way to delete repeating values when they are entered into excel.

    Example.

    Column A
    Row1 12
    Row2 13
    Row3 12

    I need row 3 to be automaticaly deleted (the whole row.) what I am doing is importing data from another workbook, but that data will contain previouse information that has already been imported and I need to delete that previouse information after I past in the data. Is there a way that Excel will search for the recuranse and delete the row where it happens.

    Thank you.

  2. #2
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    Where does the new data get in imported to ? after the last row of the existing data?
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  3. #3
    Registered User
    Join Date
    11-16-2006
    Posts
    80
    Try:

    Sub FixDuplicateRows() 'deletes Duplicate row
    Dim RowNdx As Long
    Dim ColNum As Integer
    ColNum = Selection(1).Column
    For RowNdx = Selection(Selection.Cells.Count).Row To _ 
            Selection(1).Row + 1 Step -1
        If Cells(RowNdx, ColNum).Value = Cells(RowNdx - 1, ColNum).Value Then
            Rows(RowNdx & ":" & RowNdx).select
            Selection.Delete
        End If
    Next RowNdx
    End Sub
    Got this from C Pearson (http://www.cpearson.com/excel/duplicat.htm)website and adapted it to suit yours. Might not be what your looking for though!

    HTH,
    mccreaso

  4. #4
    Registered User
    Join Date
    11-16-2006
    Posts
    80
    Just came across this:

    Public Sub DeleteDuplicateRows()
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' DeleteDuplicateRows
    ' This will delete duplicate records, based on the Active Column. That is, 
    ' if the same value is found more than once in the Active Column, all but 
    ' the first (lowest row number) will be deleted.
    '
    ' To run the macro, select the entire column you wish to scan for 
    ' duplicates, and run this procedure.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Dim R As Long
    Dim N As Long
    Dim V As Variant
    Dim Rng As Range
    
    On Error GoTo EndMacro
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    
    Set Rng = Application.Intersect(ActiveSheet.UsedRange, _ 
                        ActiveSheet.Columns(ActiveCell.Column))
    
    Application.StatusBar = "Processing Row: " & Format(Rng.Row, "#,##0")
    
    N = 0
    For R = Rng.Rows.Count To 2 Step -1
    If R Mod 500 = 0 Then
        Application.StatusBar = "Processing Row: " & Format(R, "#,##0")
    End If
    
    V = Rng.Cells(R, 1).Value
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Note that COUNTIF works oddly with a Variant that is equal to vbNullString.
    ' Rather than pass in the variant, you need to pass in vbNullString explicitly.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    If V = vbNullString Then
        If Application.WorksheetFunction.CountIf(Rng.Columns(1), vbNullString) > 1 Then
            Rng.Rows(R).EntireRow.Delete
            N = N + 1
        End If
    Else
        If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then
            Rng.Rows(R).EntireRow.Delete
            N = N + 1
        End If
    End If
    Next R
    
    EndMacro:
    
    Application.StatusBar = False
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    MsgBox "Duplicate Rows Deleted: " & CStr(N)
    
    End Sub
    @ http://www.cpearson.com/excel/deleting.htm , exactly what your looking for?

    mccreaso

  5. #5
    Registered User
    Join Date
    05-18-2007
    Posts
    13
    MCCREASO!! That is exactly what I needed thank you!

+ 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