Results 1 to 17 of 17

Reformat data - multiple Columns to rows

Threaded View

mfusfw Reformat data - multiple... 10-31-2022, 06:08 PM
seercoven Re: Reformat data - multiple... 10-31-2022, 10:19 PM
mfusfw Re: Reformat data - multiple... 11-07-2022, 04:37 PM
seercoven Re: Reformat data - multiple... 11-07-2022, 08:19 PM
mfusfw Re: Reformat data - multiple... 11-08-2022, 01:55 PM
jindon Re: Reformat data - multiple... 10-31-2022, 11:51 PM
mfusfw Re: Reformat data - multiple... 11-08-2022, 03:12 PM
mfusfw Re: Reformat data - multiple... 11-30-2022, 04:25 PM
alansidman Re: Reformat data - multiple... 11-01-2022, 01:20 AM
mfusfw Re: Reformat data - multiple... 11-02-2022, 04:10 PM
jindon Re: Reformat data - multiple... 11-08-2022, 11:59 PM
jindon Re: Reformat data - multiple... 11-30-2022, 05:16 PM
mfusfw Re: Reformat data - multiple... 11-30-2022, 05:56 PM
jindon Re: Reformat data - multiple... 12-02-2022, 02:22 AM
mfusfw Re: Reformat data - multiple... 12-02-2022, 06:07 PM
jindon Re: Reformat data - multiple... 12-02-2022, 11:56 PM
mfusfw Re: Reformat data - multiple... 12-11-2023, 10:39 PM
  1. #8
    Registered User
    Join Date
    09-21-2021
    Location
    Los Angeles
    MS-Off Ver
    365
    Posts
    87

    Re: Reformat data - multiple Columns to rows

    Quote Originally Posted by jindon View Post
    try
    Sub test()
        Dim a, b, i As Long, ii As Long, n As Long
        With Sheets("source")
            a = .Range("a2", .Cells.SpecialCells(11)).Value
        End With
        ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 5)
        For i = 2 To UBound(a, 1)
            If a(i, 1) = "" Then Exit For
            n = n + 1: b(n, 1) = a(i, 1)
            For ii = 3 To UBound(a, 2)
                If a(i, ii) <> "" Then
                    b(n, 3) = a(1, ii): b(n, 4) = a(1, ii) & " Descreption"
                    b(n, 5) = a(i, ii): n = n + 1
                End If
            Next
            n = n - 1
        Next
        With Sheets("outcome").Cells(1).Resize(, 5)
            .EntireColumn.ClearContents
            .Value = Array("*Customer", "", "Item(Product/Service)", "ItemDescription", "*ItemAmount")
            .Rows(2).Resize(n) = b
        End With
    End Sub
    Hi Jindon,

    I just ran into something that was unexpected when you originally helped, and was wondering if there is a way to help with this as well?

    Attached is what the worksheet looks like with sample data - and what the Current and Desired Outcomes look like. I highlighted in Yellow where the changes occur in the two outcomes need to appear.

    Essentially, if the group names are the same - but the customer names different, then something different from normal would need to happen to Column B and Column G of the data.

    I did not create a new thread since this directly relates to what was being done before.



    Sub test()
        Dim a, b, i As Long, ii As Long, n As Long
        
        
        With Sheets("Totals")
            a = .Range("A1", .Cells.SpecialCells(11)).Value
        End With
        
        ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 11)
        
        For i = 2 To UBound(a, 1)
            If a(i, 1) = "" Then Exit For
                n = n + 1
                'b(n, 2) = a(i, 2)
                b(n, 2) = a(i, 2) & " - " & a(i, 1)
                'b(n, 3) = a(i, 1)
            
            For ii = 3 To UBound(a, 2)
                If a(i, ii) <> "" Then
                    b(n, 7) = a(1, ii)
                    'b(n, 8) = a(1, ii)
                    b(n, 8) = a(i, 1)
                    b(n, 11) = a(i, ii)
                    n = n + 1
                End If
            Next
            n = n - 1
        Next
        
        With Sheets("Import").Cells(1).Resize(, 11)
            .EntireColumn.ClearContents
            .Value = Array("*InvoiceNo", "*Customer", "*InvoiceDate", "*DueDate", "Terms", "Memo", "Item (Product / Service)", "ItemDescription", "ItemQuantity", "ItemRate", "*ItemAmount")
            
            
    
            .Rows(2).Resize(n) = b
        End With
    
    End Sub
    Attached Files Attached Files
    Last edited by mfusfw; 11-30-2022 at 07:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reformat data in different cells to two rows
    By KingTamo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-17-2017, 12:34 AM
  2. Replies: 9
    Last Post: 12-15-2013, 10:05 PM
  3. [SOLVED] Macro to Reformat Rows that contain date, dollar amounts, and other data
    By dean87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2013, 09:16 AM
  4. How can I reformat some rows into columns in Excel?
    By nijialagua in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2012, 02:20 PM
  5. How can I reformat some rows into columns in Excel?
    By nijialagua in forum Excel General
    Replies: 2
    Last Post: 07-23-2012, 12:38 PM
  6. Replies: 1
    Last Post: 12-21-2011, 01:50 PM
  7. [SOLVED] reformat columns to rows?
    By RickyDee in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-11-2005, 05:05 PM

Tags for this Thread

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