Results 1 to 7 of 7

Delete Duplicate rows vb needs to run on all worksheets

Threaded View

  1. #1
    Registered User
    Join Date
    04-09-2009
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    25

    Delete Duplicate rows vb needs to run on all worksheets

    Hi i have the below code which runs on deleting duplicate code which i found in an excel manual. I am having some trouble as i want to convert the code so that it will run on all worksheets i have which are numbered such as 1,2,3,4 etc.

    This is so it makes the workbook easy maintenance for when deleting or adding worksheets which happens quite regularly.

    Thanks



    Sub Delete_Duplicate_Rows()
    '
    Dim str1 As String, str2 As String
    Dim r1 As Long, r2 As Long, c As Long
    '
    Application.ScreenUpdating = False
    With Sheets("1").UsedRange
    
    '
    For r1 = .Rows.Count To 2 Step -1
    str1 = ""
    For c = 1 To .Columns.Count
    str1 = str1 & Cells(r1, c).Value
    Next c
    For r2 = r1 - 1 To 1 Step -1
    str2 = ""
    For c = 1 To .Columns.Count
    str2 = str2 & Cells(r2, c).Value
    Next c
    If str1 = str2 Then
    Rows(r1).Delete
    Exit For
    End If
    Next r2
    Next r1
    '
    End With
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by sandy.beach; 04-22-2009 at 02:03 PM. Reason: did not label as code

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