+ Reply to Thread
Results 1 to 8 of 8

How to use a Macro submit button to export results to another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    How to use a Macro submit button to export results to another worksheet

    Hello everyone,

    I'm trying to add something to a spreadsheet I've created. I want users to add their data to a worksheet and then use a submit button to send their results to another worksheet. The complex part is that this spreadsheet will be completed numerous times by numerous people, so every time 'Submit' is pressed, I'd like a new row to be added to the target worksheet to record the results, creating an overall table with everyone's results.

    I'd imagine that this query has been tackled previously, but I've had a good look around and I can't find anything that quite addresses my particular query. If someone could confirm if this is possible and offer any assistance on the macro code I'd really appreciate it. Please let me know if there's any further information I could provide.

    Regards,

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

    Re: How to use a Macro submit button to export results to another worksheet

    Can I assume that each user will add his/her data on a single row?

  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to use a Macro submit button to export results to another worksheet

    Hello, thanks for replying.

    The worksheet that users will complete will be the same for all so they won't be completing separate rows. For example, users will open the document and add information to cells B1-B5 and then the results of the calculations will appear in cells C1 and C2. I want to find a way to export the information from all aforementioned cells into a target worksheet once the information is 'submitted'.

    • User 1 opens the workbook, adds data to B1-B5 of worksheet 1, presses submit and the information is exported to row 2 of worksheet 2. The file is saved and closed.
    • User 2 opens the workbook, adds data to B1-B5 of worksheet 1, presses submit and the information is exported to row 3 of worksheet 2. The file is saved and closed.

    Essentially, worksheet 1 works as a portal to obtain the data and everything is saved on worksheet 2. I hope that is clear, sorry I can't share the file, as it contains some sensitive information.

    Regards,

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

    Re: How to use a Macro submit button to export results to another worksheet

    Assign this code to a button on your worksheet. It will also clear the range after it is copied to sheet 2 so that it is ready for new input for the next user.
    Sub CopyData()
        Range("B1:B5").Copy
        Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
        Range("B1:B5").ClearContents
    End Sub
    Last edited by Mumps1; 05-20-2013 at 11:26 AM.

  5. #5
    Registered User
    Join Date
    05-17-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to use a Macro submit button to export results to another worksheet

    That's great Mumps1! Thanks!

    Please could you advise on how to adapt the code slightly? Sheet1 also contains data in cells C1:C2; is it possible to incorporate this range into the code so that it pastes immediately after the results of B1:B5 in sheet2, i.e. in cells A2:G2 in sheet2? I've tried amending the range to B1:C2, but this pastes the information across two rows. It would also be great to have the values pasted instead of any formulae.

    Sorry for not being more specific initially.

    Regards,

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

    Re: How to use a Macro submit button to export results to another worksheet

    How about this:
    Sub CopyData()
        Range("B1:B5").Copy
        Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
        Range("C1:C2").Copy
        Sheets("Sheet2").Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
        Range("B1:B5").ClearContents
        Range("C1:C2").ClearContents
    End Sub

  7. #7
    Registered User
    Join Date
    05-17-2013
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to use a Macro submit button to export results to another worksheet

    Fantastic! Thank you so much for your help!

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

    Re: How to use a Macro submit button to export results to another worksheet

    My pleasure.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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