+ Reply to Thread
Results 1 to 7 of 7

Help writing macro to copy specific columns and paste them into other column

  1. #1
    Registered User
    Join Date
    09-24-2019
    Location
    Chicago
    MS-Off Ver
    2017
    Posts
    12

    Help writing macro to copy specific columns and paste them into other column

    Hi all,

    I've been studying VBA through an online course and literally love it. I'm glad I joined this forum for the really hard macros that I just haven't learned how to do yet...so I'm back today for some more help

    Basically, I'm trying to write a macro in the spreadsheet that I attached. This macro would take data from the FY19 tab and paste it into the Raw_data tab. This would be super easy if I wanted to copy ALL of the data from the FY19 tab but I don't. I only want to copy specific columns (without copying the headers). So, I highlighted the columns in green that I want to copy (these will not always be highlighted green but the name of the column will always be the same) from the FY19 tab.

    How would I write a macro that looks for those specific column names and pastes the data (all the way to the bottom of the column and not including the header) to Raw_data?

    Thanks in advance!
    Last edited by jsuar123; 09-30-2019 at 12:38 PM.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help writing macro to copy specific columns and paste them into other column

    Try this. I've commented it to help you understand it:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,636

    Re: Help writing macro to copy specific columns and paste them into other column

    Perhaps try using the macro recorder and come back for trimming /adapting ?

    Also lots of examples at https://www.rondebruin.nl/win/section3.htm

  4. #4
    Registered User
    Join Date
    09-24-2019
    Location
    Chicago
    MS-Off Ver
    2017
    Posts
    12

    Re: Help writing macro to copy specific columns and paste them into other column

    Quote Originally Posted by WideBoyDixon View Post
    Try this. I've commented it to help you understand it:

    Please Login or Register  to view this content.
    WBD
    Wow. Thanks for the help and the explanation.

    The LastCol variable basically makes it so that the For only runs the specific number of times right?

  5. #5
    Registered User
    Join Date
    09-24-2019
    Location
    Chicago
    MS-Off Ver
    2017
    Posts
    12

    Re: Help writing macro to copy specific columns and paste them into other column

    If I wanted to make it dynamic, say if the data in FY19 wasn't always in the same row to start, could i do this with another variable?

    Maybe add,
    Please Login or Register  to view this content.
    And then insert that variable into where the 5 is in this line
    Please Login or Register  to view this content.

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Help writing macro to copy specific columns and paste them into other column

    This will find those rows for you:

    Please Login or Register  to view this content.
    WBD

  7. #7
    Registered User
    Join Date
    09-24-2019
    Location
    Chicago
    MS-Off Ver
    2017
    Posts
    12

    Re: Help writing macro to copy specific columns and paste them into other column

    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. I need macro to open a file, copy and paste everything under specific column into workbook
    By kbenjamin827 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2018, 11:59 AM
  2. [SOLVED] Need help writing a Copy and Paste Macro
    By psabo315 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-04-2014, 11:36 AM
  3. Macro to copy data from specific columns and paste to new workbook
    By jcs2811 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2014, 10:15 PM
  4. [SOLVED] Need help writing Excel VBA code to copy and paste specific rows into a new worksheet
    By Ellen 2Excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-06-2013, 02:40 PM
  5. Replies: 8
    Last Post: 04-04-2013, 08:02 PM
  6. Copy several columns and paste into specific column on another worksheet
    By lcy_84 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-31-2012, 09:19 AM
  7. Macro to copy paste columns to specific rows
    By ohjeez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2011, 12:08 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