+ Reply to Thread
Results 1 to 9 of 9

troubleshoot pasting values in VBA Code from one sheet to another

  1. #1
    Registered User
    Join Date
    04-14-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    13

    troubleshoot pasting values in VBA Code from one sheet to another

    Hi - any hints as to why I keep getting an error on the final line?

    Please Login or Register  to view this content.
    Last edited by MVscarlet; 04-30-2009 at 07:59 PM.

  2. #2
    Registered User
    Join Date
    04-14-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Help troubleshoot pasting values in VBA Code from one sheet to another

    Hope that's better?

    So any ideas?
    Last edited by MVscarlet; 04-26-2009 at 11:06 AM.

  3. #3
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Help troubleshoot pasting values in VBA Code from one sheet to another

    hi,

    To fix your existing code (in the original post) you could just change the last line...
    Please Login or Register  to view this content.

    Or you could try the below code which I have optimised slightly by removing the un-necessary* use of "select":
    *This is the way it is recorded by the macro recorder.
    Please Login or Register  to view this content.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  4. #4
    Registered User
    Join Date
    04-14-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Help troubleshoot pasting values in VBA Code from one sheet to another

    Hi
    Thanks
    I am not 100% sure but it did not work - the debugger still stops it at the ActiveSheet.Paste line....

    What is the logic behind the
    Please Login or Register  to view this content.
    line?

    It really is confusing me because just a paste should be really straightforward and it seemed to work before...even this worked the first time - then it didn't work...any ideas?

    Thanks

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: troubleshoot pasting values in VBA Code from one sheet to another

    Ooopps!

    Sorry about that, the reason your code doesn't work is that the ".copy" is "undone" (for want of a better word) as soon as another action is done by the code (ie the "Sheets("B").Unprotect"). I would be very surprised if it had even worked once with the way the code is presented - have you change the order of the code since recording it?
    To overcome this you need to change the order of your code so that ".copy" is immediately before the ".paste".

    I included the
    Please Login or Register  to view this content.
    to deactivate the clipboard once the range had been pasted into the right place. Without this line it is possible that the range could be re-pasted if [enter] is pressed in the spreadsheet (depending what other lines of code you have). If you were to shrink the VBE window & step through the original code, you could see the dotted "copy lines" around the original range & possibly the comment "select destination & press ENTER or choose paste" at the bottom of the Excel window.

    However, I suggest using my optimised code as this is more efficient (without all the selections & associated screen flickering). The one line tecnique of using "range.copy destination" in my code prevents Excel from showing the previously mentioned comment.

    btw, to learn about specific properties & methods in VBA code, you can select the phrase in the VBE window & press [F1] to bring up the Help files.

    hth
    Rob

  6. #6
    Registered User
    Join Date
    04-14-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: troubleshoot pasting values in VBA Code from one sheet to another

    Thanksss - that was very useful

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: troubleshoot pasting values in VBA Code from one sheet to another

    I'm pleased I coud help - thanks for the feedback

    Rob

  8. #8
    Registered User
    Join Date
    05-11-2010
    Location
    Miami, FL
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: troubleshoot pasting values in VBA Code from one sheet to another

    I have pasted this the worksheet code but when I hit F5 or play, no macros show up. In fact the only macros that show up are those that I physically record. This doesn't help me b/c I want a date stamp for any time a row of data is modified.

    The security is set to low in the file.

    Please help b/c my frustration level is out of control!

    Thanks

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target(1, 1).Row > 1 Then
    With Cells(Target(1, 1).Row, "A")
    .Value = Date
    .EntireColumn.AutoFit
    End With
    End If
    End Sub

  9. #9
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: troubleshoot pasting values in VBA Code from one sheet to another

    hi Crozanski,

    Welcome to the Forum

    Can you please start a new thread for your question?
    (see the Forum Rules esp. #2)

    Also, when you start a new thread please wrap your code in "Code Tags" as per Rule #3. If you think it relevant, you can provide a link to this thread in your new thread.

    Rob

+ 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