+ Reply to Thread
Results 1 to 5 of 5

Delete double rows IF...

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Delete double rows IF...

    For a tool on the Finance department i work i'm trying to build an ecxel macro.

    To calculate our budgets i would like the macro to do the following:
    - If in Column D 2 or more rows are the same, AND if in Column C NOT the same it needs to delete the rows where in column C the data IS the same...

    - When the above is finished, it needs to look in Column D again, if 2 or more rows are the same, if this is true, add the values in column V to eachother and delete the rows, so each value in column D occurs only 1 time

    A find and delete doubles row macro i often use is this:
    Dim cDel As Long
    Dim iCtr As Long
    ' Turn off screen updating to speed up macro.
    Application.ScreenUpdating = False
    ' Get count of records to search through.
    Dim LstRw As Long
    LstRw = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    ' Loop through records.
    For iCtr = LstRw To 2 Step -1

    ' To specify a different column, change 1 to the column number.
    With Sheets("Pivot1").Cells(iCtr, "D") ' Do comparison of "above" record.
    If .Value = .Offset(-1, 0).Value Then
    ' If match is true then delete row.
    .EntireRow.Delete 'xlShiftUp
    ' Increment counter to account for deleted row.
    cDel = cDel + 1
    End If
    End With
    'End If
    Next iCtr
    ' Go to next record.

    Application.ScreenUpdating = True
    MsgBox "Done! " & cDel & " rows deleted"
    End Sub
    How can i adapt it to my new specific needs?

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Delete double rows IF...

    Hi,

    What do mean by Double rows ... Is your database already sorted or not ?

    HTH

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Delete double rows IF...

    Sorry, forgot to mention.

    Data is allready sorted A-Z decending (column D)

  4. #4
    Registered User
    Join Date
    10-22-2009
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Delete double rows IF...

    No suggestions?

  5. #5
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Delete double rows IF...

    Hi,

    To account for both columns C and D, you could test following change :

    Please Login or Register  to view this content.
    HTH

+ 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