+ Reply to Thread
Results 1 to 6 of 6

Command Button that will Copy& Paste into next empty column to the right in SAME worksheet

  1. #1
    Registered User
    Join Date
    02-27-2018
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    3

    Unhappy Command Button that will Copy& Paste into next empty column to the right in SAME worksheet

    Hi Guys,

    I am trying to create a command button that will copy a data range and paste this to the next empty column to the right when clicked. I need this to be able to work at least 10 times. I am newbie to VBA and macros. The code I was using is below;

    Private Sub CommandButton21_Click()
    Dim source As Worksheet
    Dim destination As Worksheet
    Dim emptyColumn As Long
    Set source = Sheets("Sheet1")
    Set destination = Sheets("Sheet1")
    'find empty Column (actually cell in Row 3)'
    emptyColumn =destination.Cells(3,8).End(xlToRight).Column
    If empty Column > 1 Then
    emptyColumn = emptyColumn + 1
    End if
    source.Range("B3:F76").Copy destination.Cells(3,emptyColumn)

    End Sub


    I think there is an issue with that last line? Please help!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,056

    Re: Command Button that will Copy& Paste into next empty column to the right in SAME works

    Try:
    Please Login or Register  to view this content.
    As an aside, please use code tags when posting code.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    02-27-2018
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Command Button that will Copy& Paste into next empty column to the right in SAME works

    Thank you for getting back to me so quick! Will make sure to use code tags next time. I am getting a Run-time error '424': Object Required.

    When I look to get it debugged the highlighted code is

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,056

    Re: Command Button that will Copy& Paste into next empty column to the right in SAME works

    My apologies. I forgot to change one of the sheet names.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-27-2018
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Command Button that will Copy& Paste into next empty column to the right in SAME works

    Thanks that works! Just wondered if I can have them copy to the right rather than to the left?

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,056

    Re: Command Button that will Copy& Paste into next empty column to the right in SAME works

    The macro finds the first empty cell in row 3 and pastes the copied data starting at that cell. Could you please explain in detail what you mean by:
    copy to the right rather than to the left

+ 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] Command Button Copy And Paste
    By underwater24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2016, 10:37 AM
  2. Command button and VBA - copy and paste
    By Cheesecake07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2016, 11:08 PM
  3. [SOLVED] Paste data from one worksheet to another workbook using command button
    By 4lysaabri in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-12-2014, 01:55 PM
  4. [SOLVED] Simple Copy and Paste Command Button
    By j_gideon in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-25-2013, 02:38 PM
  5. Replies: 5
    Last Post: 03-02-2013, 04:22 PM
  6. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  7. copy and paste data from one worksheet cell to another using command button
    By jasonruiz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-13-2011, 04:34 AM

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