Results 1 to 22 of 22

Copy columns from sheet 1 to sheet 2 using column heading as criteria using VBA

Threaded View

Jayant shettigar Copy columns from sheet 1 to... 07-21-2015, 08:24 AM
Parth007 Re: Copy columns from sheet 1... 07-21-2015, 09:30 AM
Jacc Re: Copy columns from sheet 1... 07-21-2015, 10:09 AM
Doc.AElstein Re: Copy columns from sheet 1... 07-21-2015, 11:45 AM
Jacc Re: Copy columns from sheet 1... 07-21-2015, 12:03 PM
Doc.AElstein Re: Copy columns from sheet 1... 07-21-2015, 12:12 PM
Doc.AElstein Re: Copy columns from sheet 1... 07-21-2015, 12:34 PM
apo Re: Copy columns from sheet 1... 07-21-2015, 01:00 PM
Doc.AElstein Re: Copy columns from sheet 1... 07-21-2015, 05:35 PM
Marc L Hi ! Try this demonstration ! 07-21-2015, 01:07 PM
Jacc Re: Copy columns from sheet 1... 07-21-2015, 02:00 PM
Marc L Re: Copy columns from sheet 1... 07-21-2015, 02:04 PM
Doc.AElstein Re: Copy columns from sheet 1... 07-21-2015, 04:37 PM
Jacc Re: Copy columns from sheet 1... 07-21-2015, 02:09 PM
Jacc Re: Copy columns from sheet 1... 07-21-2015, 02:15 PM
Doc.AElstein Re: Copy columns from sheet 1... 07-21-2015, 04:36 PM
apo Re: Copy columns from sheet 1... 07-21-2015, 06:54 PM
Jacc Re: Copy columns from sheet 1... 07-21-2015, 07:06 PM
Jayant shettigar Re: Copy columns from sheet 1... 07-22-2015, 04:07 AM
Doc.AElstein Re: Copy columns from sheet 1... 07-22-2015, 01:13 PM
Doc.AElstein Re: Copy columns from sheet 1... 07-22-2015, 01:40 PM
Jacc Re: Copy columns from sheet 1... 07-22-2015, 05:34 AM
  1. #2
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Copy columns from sheet 1 to sheet 2 using column heading as criteria using VBA

    Hi Jayant,

    In Below code you can add the column names accordingly & make it in use... this will work Header wise
    This code is only for 5 columns till Debit...

    Something like this can be shorten & used

    
    
    Option Compare Text ' this line code remove the diffrence between Date and date
    Sub heading()
    Dim Lastrow As Long
    
    With Worksheets("Output")
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    End With
    
    Sheets("Output").Activate   'to clear sheet2 "A" column
    Range("A3:A" & Lastrow).ClearContents
    
    
    Sheets("Dump").Activate
    Cells(1, Columns.Count).End(xlToLeft).Select
    Range(ActiveCell, Range("A2")).Select
    
    
    For Each cell In Selection
    If cell.Value = "DOCUMENT_SOURCE" Then
    cell.EntireColumn.Copy
    Sheets("Output").Activate
    Range("A1").Select
    ActiveSheet.Paste
    End If
    Next cell
    
    Application.CutCopyMode = False
    End Sub
    
    
    Sub heading1()
    Dim Lastrow As Long
    
    With Worksheets("Output")
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    End With
    
    Sheets("Output").Activate   'to clear sheet2 "A" column
    Range("B3:B" & Lastrow).ClearContents
    
    
    Sheets("Dump").Activate
    Cells(1, Columns.Count).End(xlToLeft).Select
    Range(ActiveCell, Range("F2")).Select
    
    
    For Each cell In Selection
    If cell.Value = "SOURCE_DOCUMENT_DATE" Then
    cell.EntireColumn.Copy
    Sheets("Output").Activate
    Range("B1").Select
    ActiveSheet.Paste
    End If
    Next cell
    
    Application.CutCopyMode = False
    End Sub
    
    Sub heading2()
    Dim Lastrow As Long
    
    With Worksheets("Output")
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    End With
    
    Sheets("Output").Activate   'to clear sheet2 "A" column
    Range("C3:C" & Lastrow).ClearContents
    
    
    Sheets("Dump").Activate
    Cells(1, Columns.Count).End(xlToLeft).Select
    Range(ActiveCell, Range("D2")).Select
    
    
    For Each cell In Selection
    If cell.Value = "SOURCE_DOCUMENT_NUMBER" Then
    cell.EntireColumn.Copy
    Sheets("Output").Activate
    Range("C1").Select
    ActiveSheet.Paste
    End If
    Next cell
    
    Application.CutCopyMode = False
    End Sub
    
    Sub heading3()
    Dim Lastrow As Long
    
    With Worksheets("Output")
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    End With
    
    Sheets("Output").Activate   'to clear sheet2 "A" column
    Range("D3:D" & Lastrow).ClearContents
    
    
    Sheets("Dump").Activate
    Cells(1, Columns.Count).End(xlToLeft).Select
    Range(ActiveCell, Range("M2")).Select
    
    
    For Each cell In Selection
    If cell.Value = "EVENT_TYPE" Then
    cell.EntireColumn.Copy
    Sheets("Output").Activate
    Range("D1").Select
    ActiveSheet.Paste
    End If
    Next cell
    
    Application.CutCopyMode = False
    End Sub
    
    
    Sub heading4()
    Dim Lastrow As Long
    
    With Worksheets("Output")
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    End With
    
    Sheets("Output").Activate   'to clear sheet2 "A" column
    Range("E3:E" & Lastrow).ClearContents
    
    
    Sheets("Dump").Activate
    Cells(1, Columns.Count).End(xlToLeft).Select
    Range(ActiveCell, Range("AI2")).Select
    
    
    For Each cell In Selection
    If cell.Value = "Debit" Then
    cell.EntireColumn.Copy
    Sheets("Output").Activate
    Range("E1").Select
    ActiveSheet.Paste
    End If
    Next cell
    
    Application.CutCopyMode = False
    End Sub
    
    
    
    Sub heading4()
    Dim Lastrow As Long
    
    With Worksheets("Output")
    Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    End With
    
    Sheets("Output").Activate   'to clear sheet2 "A" column
    Range("E3:E" & Lastrow).ClearContents
    
    
    Sheets("Dump").Activate
    Cells(1, Columns.Count).End(xlToLeft).Select
    Range(ActiveCell, Range("AI2")).Select
    
    
    For Each cell In Selection
    If cell.Value = "Debit" Then
    cell.EntireColumn.Copy
    Sheets("Output").Activate
    Range("E1").Select
    ActiveSheet.Paste
    End If
    Next cell
    
    Application.CutCopyMode = False
    End Sub
    Last edited by Parth007; 07-21-2015 at 09:39 AM.
    Regards
    Parth

    I appreciate your feedback. Hit * if u Like.
    Rules - http://www.excelforum.com/forum-rule...rum-rules.html

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy Columns to another sheet based on column heading
    By jhall488 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2014, 03:46 PM
  2. [SOLVED] Auto copy contents from sheets 2 and 3 to sheet 1 if column heading contains set words
    By Thomas Andrews in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 06-09-2014, 11:59 AM
  3. how to copy columns of another sheet with the column data of current sheet
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2014, 11:28 PM
  4. [SOLVED] COUNTIF with multiple criteria on several columns (different column heading)
    By rose4emi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2012, 06:41 AM
  5. [SOLVED] Search for heading in data sheet and copy range to corresponding sheet in master workbook
    By sans in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-07-2012, 10:02 AM
  6. Macro to filter based on column heading then copy and paste to new sheet
    By macattackr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2012, 05:14 PM
  7. Search for column heading and copy column onto another sheet
    By chrismann85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2008, 05:53 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