+ Reply to Thread
Results 1 to 20 of 20

Command Button Paste To Selected Worksheet By Cell Reference

  1. #1
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Command Button Paste To Selected Worksheet By Cell Reference

    Hi Guys,

    I am just wondering if there is anyway to select the paste sheet as a cell reference. I am very new to all this have the code below to copy from sheet1 and paste to sheet2 in the next available free row. Is there anyway to be able to distinguish the paste sheet by cell refence? For instance if I put "Sheet2" in Sheet1 Cell H2 it would go to the worksheet called Sheet2 but if I changed it to "Sheet3" it would go to Sheet3 etc? I could make a ton of buttons which would do the same job but I am sure there must be an easier way? Any help greatly appreciated! Current code below.

    Regards,
    Jon

    Please Login or Register  to view this content.
    Last edited by davesexcel; 09-11-2020 at 10:26 AM.

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

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    By what you describe, it sounds like you have many sheets and you want to specify which sheet will be the destination sheet by putting the sheet name in cell H2. Is this correct? Will the range to be copied always be A2:A10?
    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
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Hi Mumps,

    Yes this is correct. I want to use one button and use H2 to specify the destination sheet. At the moment I would have to create say 10 different command buttons to manually code each destination sheet.

    Regards,
    Jon

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

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    I think the easiest way to this would be to insert a drop down list of all the sheets except for Sheet1 in a drop down list in H2. All you would have to do is make a selection in the drop down list and the range A2:A10 in Sheet1 would be copied to the selected sheet. Would this work for you?

  5. #5
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    That would be fine as long as I could press something to confirm it should be sent. What I am effectively trying to do in my code is set the paste sheet to Sheet1 Cell H2. If you think it would be more efficient by using a drop down list I am more than happy to take your advice if you could point me in the right direction. The only time I have really used drop downs is in data validation in dashboard for formula reference.

    Set pasteSheet = Worksheets("Sheet1CellH2")

    Regards,
    Jon

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

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    confirm it should be sent
    By this I assume that you mean if the range should be copied/pasted. Is this correct?

  7. #7
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Yes. So almost like selecting the sheet and then pressing go.

  8. #8
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Assuming your range is fixed from A2:A10 & destination sheet name in cell H2, try the below code
    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  9. #9
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Hi,

    Thanks for the input. My range is actually from F7:K21 & Sheet1 (Where the button will be is currently named "Front" to be pasted in columns A-F so I amended the code to that below and it didn't like it.. Unsure if it is because I haven't edited correctly.

    Private Sub CommandButton1_Click()

    Sheets(Sheets("Front").[H2].Value).Range("A:F" & Rows.Count).End(3).Offset(1).Resize(9) = Sheets("Front").[F7:K21].Value

    End Sub

    Regards,
    Jon

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Copy and paste these macros into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Click on H2 and make a selection.
    Please Login or Register  to view this content.
    This assumes your "Front" sheet is the first sheet.
    Last edited by Mumps1; 09-11-2020 at 11:14 AM.

  11. #11
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Quote Originally Posted by Shortbred View Post
    Unsure if it is because I haven't edited correctly
    Try this ...
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Quote Originally Posted by nankw83 View Post
    Try this ...
    Please Login or Register  to view this content.
    Still not liking this one either.

  13. #13
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    What happens ? Are you getting an error ? Can you post a small sample workbook ?

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Have you tried the code I suggested in Post #10?

  15. #15
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Quote Originally Posted by Mumps1 View Post
    Have you tried the code I suggested in Post #10?
    This one works. Thank you so much! Is there a way to ignore the first 4 tabs instead of just the first one?

  16. #16
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Quote Originally Posted by nankw83 View Post
    What happens ? Are you getting an error ? Can you post a small sample workbook ?
    This one is also working now. Brilliant. I just had to change the Range to A that's all. Thanks for your help See code below:

    Private Sub CommandButton1_Click()

    Sheets(Sheets("Front").[H2].Value).Range("A" & Rows.Count).End(3).Offset(1).Resize(15, 6) = Sheets("Front").[F7:K21].Value

    End Sub

  17. #17
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    I was just re-reading your post #9 & was going to suggest the same ... Glad you got it figured out. You have 2 options now

    If that takes care of your original question, please mark this thread as [SOLVED] from the Thread Tools above your first post & consider Add Reputation to those who have helped by clicking the star icon under their usernames

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Replace this line of code:
    Please Login or Register  to view this content.
    with this one:
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    07-13-2020
    Location
    Uk
    MS-Off Ver
    2016
    Posts
    16

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Top work guys. Thank you very much.

  20. #20
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Command Button Paste To Selected Worksheet By Cell Reference

    Glad to help .. Thank you for your feedback & for the add Rep.

+ 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. Command Button that will Copy& Paste into next empty column to the right in SAME worksheet
    By Kenyanbanker in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-27-2018, 03:49 PM
  2. [SOLVED] copy selected row and paste it to another sheet command button vba
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2014, 03:22 AM
  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. Command button cell reference.
    By milo1984 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2013, 05:25 PM
  5. Using a command button to copy selected data to another worksheet
    By 02.flea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2012, 02:12 AM
  6. Replies: 2
    Last Post: 06-11-2012, 05:14 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

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