+ Reply to Thread
Results 1 to 8 of 8

Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

  1. #1
    Registered User
    Join Date
    05-05-2014
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2013
    Posts
    9

    Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    Hello all,

    I've run into an issue working on a small project. I hope you can help!

    The project:

    A workbook in which sheet 1 is a form for people to input into 2 adjacent columns time spent on different tasks at the end of each work week. Sheet 2 is identical to sheet 1, but has the intended purpose of storing the data input into the form in sheet 1.

    There is a button at the bottom of the form in sheet 1 with an assigned macro that effectively transfers all the data to sheet 2 and then clears sheet 1 for another entry.

    The issue:

    I cannot get the data to transfer to the next available set of 2 adjacent columns in sheet 2. It keeps repopulating the first 2 columns.

    Any help on modifying the macro to transfer data to the next available set of 2 columns on sheet 2 would be much appreciated.

    Thanks!

  2. #2
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    Welcome to the forums. You will want to upload example with the code for the forms you have.
    Thank those who have helped you by clicking the Star * below their name and please mark your post [SOLVED] if it has been answered satisfactorily.

  3. #3
    Registered User
    Join Date
    05-05-2014
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    MED T&E_TEMPLATE_restructure.xlsmThanks for the heads up! Here is what I have so far:

    Please Login or Register  to view this content.

    Kind of sloppy code, I know, since this was a hastily recorded macro.

    As for the workbook itself: sheet "Form_R" is the form people will use, and sheet "Data" is where the input from Form_R is to be stored.
    Last edited by sfryeben; 05-05-2014 at 04:17 PM.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    Perhaps somthing like this?

    Please Login or Register  to view this content.
    Word of warning since you have data validation in columns D and E in sheet "Data" I could not use the "ActiveSheet.UsedRange.Columns.Count" command as this counted the empty columns as well.

    So I've use the "CountA" funtion on row 2 to find the traget column when copying so there must always be a value in both D2 and E2 in sheet "Form_R" to ensure that the next pasting is placed in the proper column.

    Alf

  5. #5
    Registered User
    Join Date
    05-05-2014
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    Thanks, Alf!

    Data validation in columns D and E of sheet "Data" was an erroneous product of testing the macro as I had it originally recorded -- it would copy over the data validation settings from sheet "Form_R".

    It is unlikely that there will always be a value in both D2 and E2 of "Form_R", so I have removed data validation. Could you explain briefly how I can use the "ActiveSheet.UsedRange.Columns.Count" command now that it is an option?

    Thanks!

    Sam

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    I had a bit of rethink and perhaps this macro wil suit you better?

    Please Login or Register  to view this content.
    Since macro uses the command "PasteSpecial xlPasteAll" this will copy the data validation formate from sheet "Form_R" to "Data" sheet so just leave this formate on "Data" sheet as the macro now takes this in account.

    After activating sheet "Data" macro first finds number of columns used i.e. for an "empty" "Data" sheet this number will be 5 on account of the data validation formatein column D and E but even if there are values in coumn D and E this value will still be 5 so I've added an extra check by testing the sum of range "D2:E50". If this is 0 then we know that the range D2:E50 is really empty and result should be copied to range D2 in sheet "Data".

    If on the other hand the sum of range "D2:E50" is not 0 i.e. not empty then data from sheet "Form_R" should be copied to Cells(2, i + 1) i.e the cell in row 2 and column 6 as both conditions must be fullfilled (i = 5 and SUM = 0) if result should be copied to range D2 in sheet "Data"

    Alf

  7. #7
    Registered User
    Join Date
    05-05-2014
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    Alf,

    Thank you so much! Unfortunately, I just solved my own problem.

    I've been working away at this all day (I've never coded before and this is really fun!). I came up with a solution by coming at it from a different angle... and reading, failing, reading some more, failing some more...

    I was able to piece together this:

    Please Login or Register  to view this content.
    MED T&E_TEMPLATE_restructure.xlsm

    I abandoned the vertically-oriented sheet "Data" for a horizontally-oriented sheet "Data_R". By using NextRow and Transpose I was able to get everything to transfer over. The Data Validation still comes along with the data, but this won't be an issue as this sheet will be locked to users of the form.

    Thank you and everyone else again for all your help! Like I said, I've never done this before and I had a lot of fun working it out! I think I'll be stopping through here more often

    Sam

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Transfer data from form to next sheet in NEXT AVAILABLE COLUMN

    Unfortunately, I just solved my own problem
    Why unfortunately? What you did is always the best ways to solve a problem because then you know what you are doing and if things go wrong it's much easier for you to fix your problem.

    So welcome back to the forum!

    Alf

    Ps I think your new sheet layout better.

+ 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. Unable to transfer data from user form to spread sheet
    By katieshields in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2014, 05:43 AM
  2. Macro to transfer data from Input sheet to summary form
    By CA_needing_help in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2013, 03:14 AM
  3. Replies: 2
    Last Post: 10-11-2011, 08:03 AM
  4. Transfer User form data to a worksheet w.r.t. combobox item on the form
    By nm766 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2011, 12:43 PM
  5. Macro To Transfer Form to New Sheet and Data to Another Sheet
    By kokoynonoy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2011, 10:36 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