+ Reply to Thread
Results 1 to 5 of 5

Copy multiple columns and paste into one column, based on row criteria

Hybrid View

Miki1989 Copy multiple columns and... 06-17-2015, 06:10 AM
GC Excel Re: Copy multiple columns and... 06-17-2015, 06:57 AM
Kamboj Re: Copy multiple columns and... 06-17-2015, 07:33 AM
Kamboj Re: Copy multiple columns and... 06-17-2015, 07:36 AM
Miki1989 Re: Copy multiple columns and... 06-17-2015, 09:59 AM
  1. #1
    Registered User
    Join Date
    09-25-2013
    Location
    Tbilisi, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question Copy multiple columns and paste into one column, based on row criteria

    Hi,
    I am newbie in VBA, but know excel formulas in advance level.. So I will appreciate any help and supported provided..
    I have searched the forums for what I need but nothing was matching

    So,
    I have an excel sheet with several rows and columns.
    In each row there are City name & Dates and in each columns have sales by different Units (A1, A2, A3 etc..)

    Please find below raw data:
    on3ZP0W.jpg

    What I want to see is :
    jB8wdEN.jpg

    Also you can download workbook from following link: https://app.box.com/s/kj3fixsl13cfikhgt15p7fr63ogzdnvs
    There is two sheet - Raw Data & What I want to see


    Thank you in advance!!!!

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Copy multiple columns and paste into one column, based on row criteria

    Hello,

    Try this code:
    (change the input range and output destination cell as required)

    Sub FlatData()
        Dim ar, arF
        Dim i As Long, j As Long, n As Long
    
        ar = Sheets(1).Range("B2").CurrentRegion.Value  'Range of data
        n = UBound(ar, 2)
    
        ReDim arF(1 To UBound(ar, 1) * n, 1 To 3)
        n = 1
        For i = 2 To UBound(ar, 1)   '2 to skip header row
            For j = 3 To UBound(ar, 2)
                arF(n, 1) = ar(i, 1)
                arF(n, 2) = ar(i, 2)
                If ar(i, j) <> "" Then
                    arF(n, 3) = ar(i, j)
                    n = n + 1
                End If
            Next j
        Next i
        Sheets(2).Cells(1).Resize(n - 1, 3) = arF 'Output to different sheet (must exist)
    
    End Sub
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: Copy multiple columns and paste into one column, based on row criteria

    use can use this code with a new sheet name Data
    Sub copy_mlt_2_onecol()
    a = 3
    n = 4
    b = 3
    Do Until b = 833
    Do Until n = 31
    Sheets("Data").Cells(a, 2).Value = Sheets("Raw Data").Cells(b, 2).Value
    Sheets("Data").Cells(a, 3).Value = Sheets("Raw Data").Cells(b, 3).Value
    Sheets("Data").Cells(a, 4).Value = Sheets("Raw Data").Cells(2, n).Value
    Sheets("Data").Cells(a, 5).Value = Sheets("Raw Data").Cells(b, n).Value
    n = n + 1
    a = a + 1
    Loop
    n = 4
    b = b + 1
    Loop
    End Sub

  4. #4
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: Copy multiple columns and paste into one column, based on row criteria

    Here is your excel sheet, run the macro and u will get the result.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-25-2013
    Location
    Tbilisi, Georgia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Copy multiple columns and paste into one column, based on row criteria

    Thank you for genial solution!!!

    Thank you all 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] Copy and paste columns to another sheet based on a criteria
    By saya_26 in forum Excel General
    Replies: 17
    Last Post: 02-24-2014, 12:23 PM
  2. [SOLVED] Copy/Paste a column in a new sheet based on a criteria
    By Elorac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2013, 02:01 PM
  3. [SOLVED] Copy/Paste multiple columns as values based on another columns criteria
    By Dgp2012 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-28-2013, 06:50 AM
  4. Create new tab + paste columns based on multiple criteria
    By imatias in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2012, 11:00 AM
  5. Copy and Paste and Delete Columns Based on Criteria
    By datalogger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2010, 01:07 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