+ Reply to Thread
Results 1 to 5 of 5

Transform column to row. And marge some data.

Hybrid View

  1. #1
    Registered User
    Join Date
    09-26-2016
    Location
    en
    MS-Off Ver
    2010
    Posts
    3

    Transform column to row. And marge some data.

    Hi,

    It sounds easy, but it's not. Sample data in attachment. What i have, and what i need.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,844

    Re: Transform column to row. And marge some data.

    Add a sheet and name it "Sheet1". Select your Arkusz1 sheet. The macro assumes that you have headers in row 1 and your data is in columns A and B starting in row 2. Try:
    Sub dosi()
        Application.ScreenUpdating = False
        Dim rngUniques As Range
        Dim rng As Range
        Dim LastRow As Long
        LastRow = Sheets("Arkusz1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Sheets("Arkusz1").Range("A1:A" & LastRow).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
            ("A1:A" & LastRow), Unique:=True
        Set rngUniques = Sheets("Arkusz1").Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible)
        If Sheets("Arkusz1").FilterMode Then Sheets("Arkusz1").ShowAllData
        For Each rng In rngUniques
            Range("A1:B" & LastRow).AutoFilter Field:=1, Criteria1:=rng
            Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) = rng
            Range("B2:B" & LastRow).SpecialCells(xlCellTypeVisible).Copy
            Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
        Next rng
        If Sheets("Arkusz1").FilterMode Then Sheets("Arkusz1").ShowAllData
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    10-15-2013
    Location
    Hawaii
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Transform column to row. And marge some data.

    or another option (a bit more flexible):
    Public Sub test()
        
        'Settings
        Dim intStartRow As Integer
        Dim intHeaderCol As Integer
        Dim intDataCol As Integer
        Dim intPasteRow As Integer
        Dim intPasteCol As Integer
        
        'Current Data Point
        Dim intCurrentRow As Integer
        Dim strCurrentHead As String
        Dim strData As String
        Dim strTransposeHead As String
        Dim intCurrentPasteRow As Integer
        Dim intCurrentPasteCol As Integer
        
        
        'Initialize
        intStartRow = 3
        intHeaderCol = 1
        intDataCol = intHeaderCol + 1
        intPasteRow = intStartRow
        intPasteCol = intDataCol + 5
        intCurrentPasteRow = intPasteRow - 1
        intCurrentPasteCol = intPasteCol
        
        'Grab first data point
        intCurrentRow = intStartRow
        strCurrentHead = ActiveSheet.Cells(intCurrentRow, intHeaderCol).Value2
        strData = ActiveSheet.Cells(intCurrentRow, intDataCol).Value2
        strTransposeHead = vbNullString
        
        'Loop until a data until a blank header is found
        Do While (strCurrentHead <> vbNullString)
            If strCurrentHead <> strTransposeHead Then
                strTransposeHead = strCurrentHead
                intCurrentPasteRow = intCurrentPasteRow + 1
                intCurrentPasteCol = intPasteCol
                ActiveSheet.Cells(intCurrentPasteRow, intPasteCol) = strCurrentHead
            End If
            intCurrentPasteCol = intCurrentPasteCol + 1
            ActiveSheet.Cells(intCurrentPasteRow, intCurrentPasteCol) = strData
            
            'Increment
            intCurrentRow = intCurrentRow + 1
            strCurrentHead = ActiveSheet.Cells(intCurrentRow, intHeaderCol).Value2
            strData = ActiveSheet.Cells(intCurrentRow, intDataCol).Value2
        Loop
    End Sub

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,950

    Re: Transform column to row. And marge some data.

    another option

    Option Explicit
    
    Sub dosi()
        Dim s1 As Worksheet, s2 As Worksheet
        Dim i As Long, lr As Long, lc As Long, lr2 As Long
        Set s1 = Sheets("Arkusz1")
        Set s2 = Sheets("Sheet1")
        lr = s1.Range("A" & Rows.Count).End(xlUp).Row
    
        With s1
            For i = 3 To lr    'change your starting row as necessary
                lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
                lc = s2.Cells(lr2, Columns.Count).End(xlToLeft).Column
                If .Range("A" & i) <> .Range("A" & i - 1) Then
                    .Range("A" & i & ":B" & i).Copy s2.Range("A" & lr2 + 1)
                Else: .Range("B" & i).Copy s2.Cells(lr2, lc + 1)
                End If
            Next i
        End With
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    09-26-2016
    Location
    en
    MS-Off Ver
    2010
    Posts
    3

    Re: Transform column to row. And marge some data.

    You are best guys!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Marge data inside Master workbook getting data multiples files based specfic sheets
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-22-2021, 07:14 AM
  2. transform data separated with comma into 1 column
    By royalB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2015, 09:39 AM
  3. Need Help: Transform Column to Row Data
    By inal30 in forum Excel General
    Replies: 2
    Last Post: 08-29-2013, 09:07 AM
  4. how to transform data from row-base to column-base
    By fei2010 in forum Excel General
    Replies: 3
    Last Post: 11-23-2012, 12:17 AM
  5. Transform 2 column table into 1 column of data
    By amiller in forum Excel General
    Replies: 8
    Last Post: 04-11-2011, 01:29 PM
  6. Transform data in column to rows
    By wisconsin262 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2008, 06:38 PM
  7. Transform row to a column
    By dealwi8me in forum Excel General
    Replies: 3
    Last Post: 06-10-2006, 04:10 PM

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