+ Reply to Thread
Results 1 to 10 of 10

Continuous column copy / Non-continuous column paste (VBA)

  1. #1
    Forum Contributor
    Join Date
    02-05-2014
    Location
    Bay Area
    MS-Off Ver
    Excel 2010
    Posts
    164

    Continuous column copy / Non-continuous column paste (VBA)

    Hello.

    I'm a rookie to macros/VBA and to this website/forum. I appreciate any help I can get on my question (a rookie question).

    I'm slogging my way through a macro that essentially copies specific (but non-continuous) columns of raw data from one worksheet ("data") to another worksheet ("fundings"). Both worksheets are in the same workbook. The code I listed below works (albeit, it is ugly), but I'm having a hard time pasting my data differently than how I'm copying it. What I need to do is paste the data into specific (non-continuous) columns on the destination worksheet. I'm using the Union function to copy the non-continuous columns from the raw data. This function combines the non-continuous columns and makes them look continuous. There are nine columns selected in "data" (see code below), and this data is then pasted to the first nine columns in "fundings". What I need to do is paste the results in specific columns of the destination worksheet ("fundings"). For example, I want the first-through-fourth copied columns ("A-D") to paste to the first four columns of the destination sheet (this already happens), and I want the fifth column of copied data ("G") to paste to the seventh column of the destination sheet (not working). I can't figure out how to skip columns in the pasting function.

    Apologies for being lengthy. And thanks in advance for the help.

    Please Login or Register  to view this content.
    Last edited by alansidman; 02-05-2014 at 06:40 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Continuous column copy / Non-continuous column paste (VBA)

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between
    Please Login or Register  to view this content.
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (Because you are new to the forum, I have added them for you today. Please read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    02-05-2014
    Location
    Bay Area
    MS-Off Ver
    Excel 2010
    Posts
    164

    Re: Continuous column copy / Non-continuous column paste (VBA)

    I saw another person's post, and that person did a good job of summarizing my desired results. They are as follows (using fake column labels):

    Sheet 1 - the source ("data"). Copy FROM the following columns:
    A -- B -- J -- M

    Sheet 2 - the destination ("fundings"). Copy TO the following columns:
    A -- B -- E -- F

    Thanks for any advice.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Continuous column copy / Non-continuous column paste (VBA)

    Why not do two copy and pastes. First the Union copy and paste the first 4 columns and then the last column copy and paste to column G.

  5. #5
    Forum Contributor
    Join Date
    02-05-2014
    Location
    Bay Area
    MS-Off Ver
    Excel 2010
    Posts
    164

    Re: Continuous column copy / Non-continuous column paste (VBA)

    I like that idea; however, my only problem is that I don't know how to specifically tell the second paste to start at column G.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Continuous column copy / Non-continuous column paste (VBA)

    Here is the syntax using the defined variables in your code. Hopefully, I have extracted them correctly.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-05-2014
    Location
    Bay Area
    MS-Off Ver
    Excel 2010
    Posts
    164

    Re: Continuous column copy / Non-continuous column paste (VBA)

    Thank you very much! I think I get it now. Have a nice evening.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Continuous column copy / Non-continuous column paste (VBA)

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  9. #9
    Forum Contributor
    Join Date
    02-05-2014
    Location
    Bay Area
    MS-Off Ver
    Excel 2010
    Posts
    164

    Re: Continuous column copy / Non-continuous column paste (VBA)

    One more related question. If the code above works (which it does), then why wouldn't the following code work -- choosing two columns to copy and two columns to paste? The code that worked well copies and pastes only one column. Thanks again for the help!!
    Please Login or Register  to view this content.

  10. #10
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Continuous column copy / Non-continuous column paste (VBA)

    That's because to reference 2 columns, you need to specify the start row for the start column as well, i.e. C10:D20. What you have done was only C:D20, for example.

    Try changing to:
    Please Login or Register  to view this content.
    Note: the CStr() is most likely unnecessary too
    多么想要告诉你 我好喜欢你

+ 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] Auto copy from upper cells in dis-continuous data in column
    By JawadAhmed in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 04-14-2013, 09:31 AM
  2. Column contents to continuous text
    By Firemaster in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 10-16-2012, 08:12 AM
  3. [SOLVED] Ranking In a Non-Continuous Column
    By DawginAuburn in forum Excel General
    Replies: 4
    Last Post: 09-13-2012, 09:51 AM
  4. Copy not continuous ranges and paste it new word file
    By suny100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2012, 02:16 PM
  5. add cells conditionaly not in continuous row or column
    By loganinc6 in forum Excel General
    Replies: 3
    Last Post: 11-10-2005, 11:45 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