+ Reply to Thread
Results 1 to 8 of 8

Copy and Paste Transpose using VBA

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    balikpapan
    MS-Off Ver
    Excel 2016
    Posts
    15

    Copy and Paste Transpose using VBA

    Hi MVPs

    i currently working on a list which contains several data horizontally, i want to make the data vertically, like transpose copy and paste. however there are over 1000 rows, and the data is not always same length like this :
    description material 1 no material 2 no material 3 no material 4 no
    Car Maintenance Lubricant 1 Tire 4 Paint Polish 1 Soap 1
    Bicycle Maintenance Chain Lube 1 Tire 2 blank blank blank blank

    and so on, i want to make it like this :
    description material no
    Car Maintenance Lubricant 1
    Blank Tire 4
    Blank Paint Polish 1
    Blank Soap 1
    Bicycle Maintenance Chain Lube 1
    blank Tire 2

    and so on. it's easy to make it by using transpose copy and paste, however, i think it must insert number of rows first, then trasnpose paste it. But with over 1000 rows, it will take times, maybe there are some VBA codes to make it easier

    Thank you for your help

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Copy and Paste Transpose using VBA

    Please see yellow banner on how to attach a sample workbook.

    and are you still using Excel 2010: if not please update your profile with your current version.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    balikpapan
    MS-Off Ver
    Excel 2016
    Posts
    15

    Re: Copy and Paste Transpose using VBA

    Quote Originally Posted by JohnTopley View Post
    Please see yellow banner on how to attach a sample workbook.

    and are you still using Excel 2010: if not please update your profile with your current version.
    Sorry for my confusing thread, here it is
    Sample Transpose.xlsx

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Copy and Paste Transpose using VBA

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Copy and Paste Transpose using VBA

    Gee, John, that looks awfully familiar. You beat me to it!
    My very similar solution assumes there's only one table on the sheet, and re-formats it to display the new "data shape":
    Please Login or Register  to view this content.
    @abduldedysubhansyah - To simplify filtering, you might want to consider including the description on every row. The code could be modified to do so very easily.
    Attached Files Attached Files
    Last edited by leelnich; 06-30-2023 at 08:42 AM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

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

    Re: Copy and Paste Transpose using VBA

    An alternative to VBA is Power Query where you can unpivot your data

    Please Login or Register  to view this content.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Attached Files Attached Files
    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

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this !


    A VBA demonstration just revamping table #1 :

    PHP Code: 
    Sub Demo1()
            
    Dim VR&, W(), C%, L&
        
    With Sheets("Sheet2").ListObjects(1)
        If .
    ListColumns.Count And (.ListColumns.Count And 1Then
            V 
    = .DataBodyRange
            R 
    Application.CountA(V):  If Or R Mod 3 Then Beep: Exit Sub
            ReDim W
    (1 To R 31 To 3)
        For 
    1 To UBound(V)
        For 
    2 To UBound(V2Step 2
            
    If Not IsEmpty(V(RC)) Then L 1W(L1) = V(R1): W(L2) = V(RC): W(L3) = V(R1)
        
    Next CR
           
    .Range.Columns(4).Resize(, .ListColumns.Count 3).EntireColumn.Delete
           
    .Range.Range("B1:C1") = Array("Material""No")
            If 
    L Then .DataBodyRange.Resize(L) = W
           
    .Range.Columns.AutoFit
        End 
    If
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-30-2023 at 09:09 AM. Reason: optimization ...

  8. #8
    Registered User
    Join Date
    10-10-2012
    Location
    balikpapan
    MS-Off Ver
    Excel 2016
    Posts
    15

    Re: Copy and Paste Transpose using VBA

    johnTopley & leelnich

    please accept the star to both of you, both solution is exactly what i need. this thread is SOLVED

    thank you so much

+ 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] Copy, Transpose & Paste
    By Vcare in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-01-2018, 09:10 AM
  2. [SOLVED] Copy Transpose Paste
    By Vcare in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2017, 04:34 AM
  3. copy and paste with transpose
    By atwy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2015, 10:24 AM
  4. copy paste transpose
    By alexanderdeluna in forum Excel General
    Replies: 2
    Last Post: 09-19-2013, 06:32 PM
  5. Copy from Array in ActiveWorkbook to ThisWorkbook; Transpose copy, Offset Paste
    By sbradley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2013, 05:17 PM
  6. Transpose without copy and paste
    By SSS777 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-10-2013, 02:24 AM
  7. for each sh copy paste value and transpose
    By mhni in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-04-2009, 01:51 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