+ Reply to Thread
Results 1 to 11 of 11

Copy-paste a row based on a column range value keeping the formatting and size.

  1. #1
    Registered User
    Join Date
    03-16-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Lightbulb Copy-paste a row based on a column range value keeping the formatting and size.

    Hi there,

    I'am trying for a few days to create a code for my Macro to copy-paste a row above a specific column range value keeping the formatting and merging cells into consideration when copying.
    Just an explanation of what I'm trying to achieve:

    I have two action lists which by default have two rows to be filled. In case that there may be an item that requires additional action I want to be able to have a button that when actioned to add a new row that copies the formatting and sizing of the last row from the two by default.
    Now because I have two lists I cannot use a code that specifies a specific row to be taken into consideration as that will affect the second list.
    What I need is to be able to create a code that will consider a column value where if that is value is meet, to always copy-and paste the above row above the column value.

    Please see the attached photo to have a better idea, as maybe my explanation is not so great

    Excel Macro Copy-Paste.PNG

    Please let me know if you can help.

    Until now, this is the code that I use and it's working but does not copy the format and size it's just adding a row based on the column range value.

    Please Login or Register  to view this content.
    Kind regards,
    Al
    Last edited by nadgobb; 03-16-2019 at 06:29 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    No sample file needed, the task is simple enough to do without.

    Start by deleting the numbers in column AA, you don't need those to find the end of the tables, the position of the button is an easier way to do it.

    Next move the buttons down slightly, so that the top left corner of each button is in the empty row below the table that it relates to (I would suggest increasing the height of the empty row beteen the tables to avoid confusion).

    Finally enter this code and link both buttons to it (this will work with any number of buttons following the same pattern).
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-16-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Hi,

    I've attached a sample with more comments.

    Hope it's attached.

  5. #5
    Registered User
    Join Date
    03-16-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Hi Jason,

    Thanks for your support.

    I've tried your code and I receive an error which says this:

    Jason's code error.PNG

    After changing my code to look like this:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Which button type did you use, I'm guessing that you perhaps have ActiveX buttons, not Form buttons?

    I'm not sure if they can be called in the same way, bear with me while I look into it.

    You will need to move the button for the bottom table down as well, otherwise the code will insert between the last 2 rows instead of adding to the bottom.

    edit:-

    Just had a quick look into what is needed, it would be much simpler if you could replace the activex buttons with form control buttons, I've only done a small amount of research, but it looks as if the activex buttons are less versatile.
    Last edited by jason.b75; 03-16-2019 at 08:44 AM.

  7. #7
    Registered User
    Join Date
    03-16-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    hi Jason,

    I've used the ActiveX buttons.

    Yes sure, ill do same for the bottom button as well after ill make the first one to work

    many thanks

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Hi, Not sure if you noticed my edit above, just to reiterate, the code as it stands will work with a Form control button, but not ActiveX. It would be much simpler if you could change the buttons to a form control type rather than trying to make it work with an activex button (assuming that it is even possible to make it work with them).

    Also, I was trying to see what you had changed with the code, the only difference I notice was that you added 1 to the end of CommandButton in the first line. For information, you don't actually need that to make it work that is just the default naming so that you can identify which code relates to which button. As long as you right click the button in design mode, then assign the relevant macro it will work regardless of name.

    I only removed the 1 from the name to make it appear more generic because both buttons can be assigned to the same piece of code, there is no need to repeat it for each button.

  9. #9
    Registered User
    Join Date
    03-16-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Hi Jason,

    Thank you, I've tried it and it's working and does copy paste also the formatting.

    The only issue is that the button works to add the new row at the bottom list just for the first line added, if I add two, then the button is not anymore underneath the last row so it will not add the new one at the bottom list. The button is not moving with the new row added, is fix.

    Is there anything that can be done to ensure that the button always goes down simultaneously one row down to ensure it's adding always the new row to the bottom list?
    Last edited by nadgobb; 03-16-2019 at 09:25 AM.

  10. #10
    Registered User
    Join Date
    03-16-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    Hi,

    I've found a way by changing the settings of the button to always move with the line.

    Great, it's working now perfectly!

    Many thanks!

  11. #11
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Copy-paste a row based on a column range value keeping the formatting and size.

    When I tested the code before posting, the button was moving down as the new rows were inserted.

    A couple of checks.

    Did you make any changes to the code?

    Are the buttons definitely in the correct place when you start? With the top left corner of the button in the empty row and in column X. The code works on a specified number of columns, so if the button is too far right then it could be out of range. If this is the case, then which column are the buttons in now?

    edit:-

    Maybe I had that setting on already and didn't realise it. I don't work with buttons, etc. very often so it's quite easy to overlook settings like this
    Last edited by jason.b75; 03-16-2019 at 09:38 AM.

+ 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. Copy and Paste Keeping Destination formatting
    By mrcois in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-12-2018, 04:43 AM
  2. [SOLVED] Copy comments to a new range of the same size (without using copy, paste)
    By Jonathan78 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2016, 02:01 PM
  3. Need VBA to copy and paste a formula in a column based in a column range
    By nateg123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2015, 06:43 AM
  4. copy paste based on column range
    By dvnr_76 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2014, 10:54 AM
  5. [SOLVED] Copy and Paste Range of Cells based on # of cell values in Column A
    By bwaite87 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-17-2014, 05:51 PM
  6. Montlhy copy paste column keeping formulas in multiple sheets
    By pmprego in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2013, 11:18 AM
  7. Copy range from worksheet based on data in a column and paste to end of another ws
    By DavyNixon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-18-2005, 01:29 PM

Tags for this Thread

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