+ Reply to Thread
Results 1 to 3 of 3

Macro to sort a list with duplicates and add bottom border for last duplicate

Hybrid View

kuntilfusk7 Macro to sort a list with... 08-10-2012, 06:23 AM
StephenR Re: Macro to sort a list with... 08-10-2012, 07:05 AM
kuntilfusk7 Re: Macro to sort a list with... 08-10-2012, 09:44 AM
  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    DK
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro to sort a list with duplicates and add bottom border for last duplicate

    Hi,

    I am new to this forum. Most of my macro experience is based on recording macros and doing a little cleanup afterwards, however, these macros tend be rather long and slow. I have not been able to find an easy solution to below problem:

    I have a long list of sales orders where most have multiple order lines. I would like to sort the list by sales order (column A) and following add a bottom border for all data (columns A-C) for the last duplicate sales order.
    I have attached an example with two sheets showing how the list would look before and after running the macro

    Thanks for your help
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Macro to sort a list with duplicates and add bottom border for last duplicate

    Try thi:
    Sub x()
    
    Dim r As Long
    
    With Range("A1").CurrentRegion
        .Sort key1:=.Cells(1, 1), order1:=xlAscending, key2:=.Cells(1, 2), order2:=xlAscending
        For r = 2 To Rows.Count - 1
            If .Cells(r, 1) <> .Cells(r + 1, 1) Then
                With .Cells(r, 1).Resize(, 3).Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
            End If
        Next r
    End With
    
    End Sub

  3. #3
    Registered User
    Join Date
    08-09-2012
    Location
    DK
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to sort a list with duplicates and add bottom border for last duplicate

    Awesome - works like a charm
    Thanks a lot for your help!

+ 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