+ Reply to Thread
Results 1 to 15 of 15

Copy range and paste to next blank column

  1. #1
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Copy range and paste to next blank column

    I have been trying to get VBA to copy a range and paste the values into the next blank column in a range.
    I'm working with the following code:

    Please Login or Register  to view this content.
    This has been the closest I could find to what I needed, except this goes farther right than I need. I need the code to find the next available column in a range and paste there, instead of finding the cell after that last non-blank.

    I'm sure I'm missing something simple.

    Thanks.
    John

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Copy range and paste to next blank column

    Hiya,

    Could you provide a sample workbook that we can review? It would help us work through your use case requirements. Thank you!

  3. #3
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Poizhan,

    Could not upload anything due to policy. But here is a subset of data. Columns G and H are titles and daily numbers calculated from another worksheet. I want to copy H2 through H6 and paste the values into the next available column between A and F.

    A B C D E F G H
    10/2/2018 10/3/2018 DataSets 10/4/2018
    4 6 Data1 11
    3 4 Data2 6
    11 15 Data3 17
    8 8 Data4 10
    6 4 Data5 4

    I hope that helps. I think I'll start using CSV next time. Typing into the table is a pain lol

  4. #4
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Copy range and paste to next blank column

    Hi, this might work for you

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by 1aaaaaaaaaaaaaaa; 10-12-2018 at 03:34 PM.

  5. #5
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Quote Originally Posted by Poizhan View Post
    Hi, this might work for you

    Please Login or Register  to view this content.
    Sweet!! One alteration, can we make that past values only?

  6. #6
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Copy range and paste to next blank column

    @F1akman, not sure what you're asking for with "can we make that past values only" sorry could you explain further

  7. #7
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Sorry, this currently pastes the copied text and all formats as is. I would end up using this in other workbooks where the data being copied may be formulas. I only want to copy the result of the formulas, similar to Right click + v to paste "values".

  8. #8
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Bumping thread to see if there is a way to get this to paste over when the source fields are calculations and not static data. I can't seem to find a way for the xlPasteValues to work with this script.

    John

  9. #9
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,473

    Re: Copy range and paste to next blank column

    Maybe like this
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    Last edited by daboho; 10-17-2018 at 08:26 PM.

  10. #10
    Forum Contributor
    Join Date
    02-12-2018
    Location
    TX
    MS-Off Ver
    MS Office 2019
    Posts
    305

    Re: Copy range and paste to next blank column

    Pretty sure that the below works...not the cleanest thing ever created but, functional.
    HTML Code: 

  11. #11
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Quote Originally Posted by Jim Clayton View Post
    Pretty sure that the below works...not the cleanest thing ever created but, functional.
    HTML Code: 
    Thank you for the script. This pasted below a bunch of other data further down the sheet. I need to paste a column of data to the next blank column in row 3, would that use columns.count? I'm trying to wrap my head around this.

  12. #12
    Forum Contributor
    Join Date
    02-12-2018
    Location
    TX
    MS-Off Ver
    MS Office 2019
    Posts
    305

    Re: Copy range and paste to next blank column

    Well that's not any good...think I sent you the wrong thing...had a few different notepad sheets open when I was messing with it. Let me see what I did here. Tks.

  13. #13
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Quote Originally Posted by daboho View Post
    Maybe like this
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    First script, I get Syntax Error on Dim rg Range.
    Second script, I get Type mismatch on If Not LEN(r.Value) Then

    I'm a bit confused on these as well. Where would I paste the copy? Sorry if I seem dense on this.

  14. #14
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,473
    Quote Originally Posted by F1akman View Post
    First script, I get Syntax Error on Dim rg Range.
    Second script, I get Type mismatch on If Not LEN(r.Value) Then

    I'm a bit confused on these as well. Where would I paste the copy? Sorry if I seem dense on this.
    I am sorri change
    Please Login or Register  to view this content.
    Last edited by daboho; 10-17-2018 at 08:27 PM.

  15. #15
    Registered User
    Join Date
    09-06-2018
    Location
    California, USA
    MS-Off Ver
    2016
    Posts
    20

    Re: Copy range and paste to next blank column

    Quote Originally Posted by daboho View Post
    I am sorri change
    Please Login or Register  to view this content.
    Not working on that one. The selected area gets copied, but nothing pastes. Not sure I get the If/End If on this one.

    Thanks

+ 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] Copy non-blank cells in a range and paste all into a single column
    By excellerant8 in forum Excel General
    Replies: 2
    Last Post: 05-03-2018, 10:53 AM
  2. Replies: 5
    Last Post: 01-31-2018, 09:48 AM
  3. [SOLVED] copy only non-blank cells in range and paste to new range.
    By scrabtree23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2015, 08:10 PM
  4. [SOLVED] Copy / Paste range from one sheet to another, if cell in column A is not blank
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2014, 09:18 AM
  5. Replies: 4
    Last Post: 03-17-2013, 05:58 AM
  6. Copy and paste non blank rows from a range
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-12-2010, 09:29 AM
  7. Copy Data from Column and Paste to Next Blank Column on 2nd Sheet
    By adammark in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2010, 11:15 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