Results 1 to 1 of 1

Copy Columns from One Table to Another

Threaded View

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Copy Columns from One Table to Another

    Copy Column Application

    The requirement to copy and paste columns from one table to another in a different order and to add formulas is very common.

    Here is a bit of code that can accomplish that task.

    It all depends on the Configuration Sheet and the Table, Table_Columns. Copy this sheet as is into your workbook and then import the module (BAS File)

    See documentation in ZIP file for more details.

    Sub CopyColumn(TableNameTo As String, TableNameFrom As String)
    Dim clC As Range            ' Pointer to TableTo column names
    Dim TypeCopy As String      ' Copy as column or formula
    
    For Each clC In Range("Table_Columns[Column To]")
        TypeCopy = Left(clC.Offset(0, 1).Value, 1)
        If TypeCopy = "=" Then
            ' It is a formula
            Range(TableNameTo & "[" & clC.Value & "]") = clC.Offset(0, 1).Value
        Else
            ' It is a columnh
            Range(TableNameFrom & "[" & clC.Offset(0, 1).Value & "]").Copy
                Range(TableNameTo & "[" & clC.Value & "]").PasteSpecial xlPasteValues
        End If
    Next clC
            
    End Sub
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA to copy and past columns of Dynamic Table Name
    By hassan khansa in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-22-2022, 06:21 AM
  2. Trying to copy a columns from one table to another table in Different workbook.
    By Oberon70 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2022, 06:56 AM
  3. [SOLVED] Copy across 9 columns of source data into 9 columns of an output table
    By nunez100 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-29-2019, 10:19 AM
  4. Copy & Paste Table Columns
    By rabbit_post in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2018, 07:50 PM
  5. Copy columns from one table to another if
    By Phleacia in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2013, 03:13 PM
  6. Copy whole table columns to new table
    By Dominicus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-19-2012, 01:48 PM
  7. [SOLVED] Copy a table from Access into 2 columns
    By Tran Hong Quang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2005, 04:06 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