Results 1 to 3 of 3

VB code to merge columns with same header

Threaded View

  1. #1
    Registered User
    Join Date
    04-02-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    79

    VB code to merge columns with same header

    I need help with a VB code to merge columns with same header. i got this code from net but not suiting my need.
    I have attached a file with expected results. Any help is greatly appreciated.
    Sub ConsolidateColumns()
        Dim Rg As Range
        Application.ScreenUpdating = False
     
        With [A1].CurrentRegion
            For C& = 2 To .Columns.Count
                P& = Application.Match(.Cells(C).Value, .Rows(1), 0)
     
                If P < C Then
                    Set Rg = .Cells(C)
     
                    Do
                        Set Rg = Intersect(.Columns(C), Rg.End(xlDown))
                        If Not Rg Is Nothing Then Rg.Copy Cells(Rg.Row, P)
                    Loop Until Rg Is Nothing
     
                    .Columns(C).Clear
                End If
            Next C
        End With
     
        Application.ScreenUpdating = True
    End Sub

    Thanks
    Shreeja
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. can i lock selected columns header name and there data
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-09-2014, 07:24 AM
  2. [SOLVED] What code can I use to hide columns with the same header?
    By connieb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2013, 08:52 PM
  3. [SOLVED] Merge duplicate rows and merge the columns (approx 10 columns)
    By adfeddon in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-02-2012, 11:19 AM
  4. [SOLVED] VBA Code to optimize and clean data - Round II Merge columns
    By JoaoVr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2012, 05:58 AM
  5. VBA code to Merge the repeated cells and sum the corresponding columns
    By kiran234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2010, 07:58 PM
  6. Merge Two Columns Based on Header
    By MSmithson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2010, 05:29 PM
  7. Replies: 1
    Last Post: 11-12-2006, 06:08 AM

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