+ Reply to Thread
Results 1 to 4 of 4

Assign which column to paste the copied data VBA

  1. #1
    Registered User
    Join Date
    06-11-2020
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    2

    Assign which column to paste the copied data VBA

    I have a button in Worksheet1 that when clicked it will copy the values from A20:M28 to Worksheet2. But I want to assign which column in Worksheet2 the values from Worksheet1 will be copied to because they have different structure. Also I wanted to copy only the cells with values but it still copied the cells without values. I am pretty new to Macro so I'm still trying to figure things out. This is what I have so far:

    Please Login or Register  to view this content.

    Worksheet 1 Structure:

    Worksheet1.png



    Worksheet 2 Result when Button is clicked:

    Capture.JPG
    Last edited by mikuhatsune01; 06-11-2020 at 01:07 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Assign which column to paste the copied data VBA

    Maybe something like this ?
    Please Login or Register  to view this content.
    I wanted to copy only the cells with values but it still copied the cells without values
    Except the cell without value is NOT the row in Date Header (Column A) in between row 20 to 28, the code above still "fill" the empty value to ws2.
    But for the row in Date Header (column A) in between row 20 to 28, it will skip this blank row although the other column in the same row has value.

    I don't know how is your data if there is a possibility where the condition there is a row in Date Header (column A) in between row 20 to 28 without value, but the other column of the same row has data. And I don't know also if you still want to copy the other column of the blank date row.
    Last edited by karmapala; 06-11-2020 at 02:52 PM.

  3. #3
    Registered User
    Join Date
    06-11-2020
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    2

    Re: Assign which column to paste the copied data VBA

    Hi, I tried your code but I get an error inside the with sh2 statement starting in ".Cells(lr, ColDate).Value = cell.Value"

    I will not copy the rows from ws1 if they do not have a date. as long as there is a date, the other columns can be empty.
    Attachment 682152
    Last edited by mikuhatsune01; 06-11-2020 at 08:54 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Assign which column to paste the copied data VBA

    Quote Originally Posted by mikuhatsune01 View Post
    Hi, I tried your code but I get an error inside the with sh2 statement starting in ".Cells(lr, ColDate).Value = cell.Value"
    My bad, I'm very sorry about that because I forgot something.

    Please change this line:
    Please Login or Register  to view this content.
    into this line
    Please Login or Register  to view this content.
    I will not copy the rows from ws1 if they do not have a date.
    Yes, the code will do nothing
    if the date column if the row between 20 to 28 is blank.


    I'm sorry I cannot see your attachment.
    It gave me a message : Invalid Attachment specified

+ 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. Paste copied data in rows not columns
    By dgibney in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2016, 04:46 AM
  2. Automatically paste copied data
    By mailosid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2016, 06:42 AM
  3. [SOLVED] Help with code to paste copied data into a destination workbook
    By Grizz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-26-2014, 06:27 AM
  4. Finding the last used cell in the active column and paste copied data
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-18-2013, 09:59 AM
  5. Bunch of data to be copied and paste
    By gan_xl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-12-2013, 07:49 AM
  6. How to paste only numeric data of a copied column
    By perfection in forum Excel General
    Replies: 8
    Last Post: 10-07-2010, 08:45 AM
  7. paste copied data from bottom to top
    By refreshplease3 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-16-2006, 09:12 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