+ Reply to Thread
Results 1 to 12 of 12

Macro paste into the next blank line

  1. #1
    Registered User
    Join Date
    03-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Macro paste into the next blank line

    Good morning

    I would need some help with a code which will allow me to copy 4 values from one active temporal worksheet (B56:B59) and paste them into another worksheet (A2:D2) named "log". I have managed to do this by using the Transpose option upon pasting (please see code below).

    I am struggling with a particular part of the code since I would need theses copied values to be pasted right under the next available blank line.

    I would appreciate any help on this.

    Thanks in advance

    *************************************************************************
    Sub save()

    ActiveSheet.Shapes("Save_button").Select

    Range("B56:B59").Select
    Selection.Copy

    Sheets("Log").Select

    Range("A2").Select

    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=True


    End Sub
    *************************************************************************

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro paste into the next blank line

    Maybe try this:

    Please Login or Register  to view this content.
    Don't forget to add code tags to your code above.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    03-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro paste into the next blank line

    Thanks for your reply.

    I have add your code but it only highlights the B56:B59 range and does not copy into the log worksheet. Perhaps I am doing something wrong.

    The transpose is only used to transform a column data into a row; if it's easier to have a workaround I am happy to modify it, but my main concern is not to overwrite the values in the log worksheet; i.e. paste values in the next blank available row.

    Thanks again

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro paste into the next blank line

    Did you change Sheets(1) to the correct sheet name?

  5. #5
    Registered User
    Join Date
    03-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro paste into the next blank line

    The active worksheet is generated temporarily by another macro to do some calculations in the process and it is assigned a name which includes the date; this means the name is dinamically changing so it cannot be defined. Is there any way to define it as active worksheet?

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro paste into the next blank line

    Maybe try this:

    Please Login or Register  to view this content.
    or you could use the code the index number like I used in the example if you know the sheet number (e.g. first = 1, second =2, etc.).

  7. #7
    Registered User
    Join Date
    03-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro paste into the next blank line

    test.xlsPlease have a look at this workbook (Test.xls).

    This workbook has two worksheets:

    1) "Farmer30-04-12" (temporal worksheet)
    2) "Log" (intended repository of results in time)

    If you look into the "Farmer30-04-12" worksheet, from top to row A54 there is the calculations (secondary for the macro). In row 54 ("Your Summary of results is") you will find the range of values to be copied to the "log" worksheet. I have implented your code and assigned it to the "Save results to log" button (row 63). If you click on it and turn into the logbook you will see the results.

    Values seem to be duplicated several times and if you turn back to "Farmer30-04-12" and click again on "Save results to log" values will be overwritten. Am I missing something?

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro paste into the next blank line

    I apologize the mistake was mine. This works fine now:

    Please Login or Register  to view this content.
    Last edited by abousetta; 05-01-2012 at 07:58 AM. Reason: Modified code

  9. #9
    Registered User
    Join Date
    03-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro paste into the next blank line

    No worries. Nevertheless, I am getting a run-time error. Please have a look at the images. I'm running an older version of excel (2003); maybe the reason?

    run-time error.jpg
    debug.jpg

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro paste into the next blank line

    OK. Tested this and now seems to work:

    Please Login or Register  to view this content.
    Last edited by abousetta; 05-01-2012 at 09:12 AM. Reason: shorter version

  11. #11
    Registered User
    Join Date
    03-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro paste into the next blank line

    Well done; you're a genious! It is working now brilliantly! Thanks very much for this!

    Thumbs up for Canada!

  12. #12
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro paste into the next blank line

    Thanks for the vote of confidence. I don't do anything special really. I just apply coding practices that I have picked up over the past few years. It is often easier when the code is shortened and simplified. In your example, I would probably have created a userform and put all the input into the form and saved in a hidden sheet. That way people get to see the form and are not distracted by the previously saved data.

    Hope this helps.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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