+ Reply to Thread
Results 1 to 3 of 3

sorting a list of customer invoices from columns into rows / customer

Hybrid View

  1. #1
    Registered User
    Join Date
    05-11-2011
    Location
    new zealand
    MS-Off Ver
    Excel 2003
    Posts
    1

    Question sorting a list of customer invoices from columns into rows / customer

    Hi All,

    Cant quite get my little macro to work.

    Basic premise is i have a table of customer records in the following format.

    Customer1 | Invoice no. | Invoice class | Due Date | Amount
    Customer1 | Invoice no. | Invoice class | Due Date | Amount
    Customer1 | Invoice no. | Invoice class | Due Date | Amount
    Customer2 | Invoice no. | Invoice class | Due Date | Amount
    Customer2 | Invoice no. | Invoice class | Due Date | Amount
    Customer3 | Invoice no. | Invoice class | Due Date | Amount

    What i need to do is to sort these records so that i have 1 row for each customer which repeats the various fields accross the row instead of listing them on multiple rows.

    e.g

    Customer1 | Invoice no. | Invoice class | Due Date | Amount | Invoice no. | Invoice class | Due Date | Amount

    Problem that i am having is remembering where the customer "changes"

    see my attempt:

    Dim LSearchRow As Integer
    Dim Ccount As Integer
    
    LSearchRow = 2
    Ccount = 0
    
         
        While Len(Range("A" & CStr(LSearchRow)).Value) > 0
        
    MARKER:
                
                Cells(CStr(LSearchRow), 2).Select
                Range(Selection, Selection.End(xlToRight)).Select
                Selection.Cut
                                  
      
                
                If Range("A" & CStr(LSearchRow)).Value = Range("A" & CStr(LSearchRow - 1)).Value Then
                
                    Ccount = Ccount + 1
                                
                    Cells(CStr(LSearchRow - Ccount), 2).Select
                    
                    Selection.End(xlToRight).Select
                    Selection.End(xlToRight).Offset(0, 1).Select
                    ActiveSheet.Paste
                    
                    LSearchRow = LSearchRow + 1
                    
                GoTo MARKER
                    
                End If
                
                
                
                
                Cells(CStr(LSearchRow), 2).Select
                Selection.End(xlToRight).Offset(0, 1).Select
                ActiveSheet.Paste
                           
                LSearchRow = LSearchRow + 1
                       
                
                
                
        Wend
    
    
        
    End Sub


    Any help would be greatly appreciated! - Still struggling with this one.
    Last edited by jr1984; 05-11-2011 at 03:14 AM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: sorting a list of customer invoices from columns into rows / customer

    Hi and welcome to the board. Unfortunately,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: sorting a list of customer invoices from columns into rows / customer

    hi, jr1984, please check attachment, press "Start". The code works with both sorted and unsorted data.
    Attached Files Attached Files

+ 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