+ Reply to Thread
Results 1 to 19 of 19

Automatically transferring data from one row to another

Hybrid View

  1. #1
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Automatically transferring data from one row to another

    Hi,

    I have this worksheet with over 3000 rows and 25 columns of data. The data starts on Row 3. It is essentially a tracker spreadsheet used by many departments in my company. The data in the 3000 rows & 25 columns is not disclosed to all departments, and is hidden and locked. What I require is to set up the worksheet so that if a user types in information in row 2 (row 1 will have the column headings), the data gets cut and paste (or transferred) to the last row of the worksheet when the user presses "Enter" or a button. Essentially, it gets added to the list. I am unfamiliar with macros and VBA but I am eager to learn. Any help is appreciated.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    To which worksheet should the row be copied?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    The row should be transferred (cut and paste) to the same worksheet...but the last row...Basically, the information that is typed should be entered to the end of the list.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    So row 2 should be deleted so other rows move up or should row 2 contents be cleared ?

  5. #5
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Row 2 contents should be cleared so that the user can type in another record should they wish. Thanks!

  6. #6
    Forum Contributor thameem127's Avatar
    Join Date
    04-06-2012
    Location
    Jeddah,Saudi Arabia
    MS-Off Ver
    Excel 2003,Excel 2007
    Posts
    321

    Re: Automatically transferring data from one row to another

    Upload sample file.

  7. #7
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    The sample file has been attached. Rows 3 to 27 have been hidden. So basically when a user types in Row 2 and presses "Enter", that row should be cleared off and the data would go into Row 28. Thanks!
    Attached Files Attached Files

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    Will column R always be the last column? Is it ok if a button is provided so you can enter the data in the row and then press the data and it gets copied to the last row?

  9. #9
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Yes, column R will always be the last column and a button will work as well, although as I am unfamiliar with VBA/macros, it would be helpful if perhaps I was walked through how the whole thing works. Thanks!

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    Try this code -
    Option Explicit
    
    Sub update_data()
    Dim lrow As Long
    
    With Worksheets("Sheet1")
        lrow = .UsedRange.Rows.Count
        .Rows("2:2").Copy
        .Range("A" & lrow + 1).PasteSpecial (xlPasteValues)
        .Range("A2:R2").ClearContents
    End With
    
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

    Or you could put a button on your sheet and assign the macro to the button.

  11. #11
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Thanks! This works perfectly except the data does not paste in Row 28 (the first unused row). Instead, it pastes a few rows after Row 28. Any idea why that is?

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    I had to calculate the lastrow (lrow) using the usedrange property. So this way, if you put any formula in A28 for example and then clear it, it still thinks that cell is used. So thats how it goes one row below. Try deleting rows 28 to 30 maybe and see if the code pastes in 28.

    If not, i will have to think of another solution.

  13. #13
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Yes that's exactly what I thought. I deleted the rows and now it works perfectly. However there is one column (Column S), which has a formula. I didn't think to mention it as the user does not have any access to it. But is there any way for the formula to fill the next row as soon the user clicks the button and populates that row?

    I had the blank rows autofilled with the formula, but as you correctly deduced: the data does not paste in that row. Thanks!

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    You mean if row 27 was the last populated row, then S28 should have the formula from S27?

  15. #15
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Yes exactly! Column S has nothing to do with any of the columns associated with user input. It is just a column for referencing purposes. It basically has the row number (i.e. ROW(S1)).

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    So either you can drag down the formula to maybe 100 rows at the outset (since its a small formula) or you could use this code -
    Option Explicit
    
    Sub update_data()
    Dim lrow As Long
    
    With Worksheets("Sheet1")
        lrow = .UsedRange.Rows.Count
        .Rows("2:2").Copy
        .Range("A" & lrow + 1).PasteSpecial (xlPasteValues)
        .Range("A2:R2").ClearContents
        .Range("S" & lrow).Formula = .Range("S" & lrow - 1).Formula
    End With
    
    End Sub

  17. #17
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Hey! Thanks! The only issue is that though it's copying the formula, it is unable to copy/fill down the cell reference. For example, it is copying the formula ROW(S27) into Row 28. So the value in S28 is shown as 27, when it should be 28. Other than that, everything else looks great!

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Automatically transferring data from one row to another

    Updated code -
    Option Explicit
    
    Sub update_data()
    Dim lrow As Long
    
    With Worksheets("Sheet1")
        lrow = .UsedRange.Rows.Count
        .Rows("2:2").Copy
        .Range("A" & lrow + 1).PasteSpecial (xlPasteValues)
        .Range("A2:R2").ClearContents
        .Range("S" & lrow + 1).FormulaR1C1 = .Range("S" & lrow).FormulaR1C1
    End With
    
    End Sub

  19. #19
    Registered User
    Join Date
    01-07-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Automatically transferring data from one row to another

    Thanks! That worked!

+ 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