+ Reply to Thread
Results 1 to 7 of 7

VBA Code is copying a single cell only. Please spot the error for me.

  1. #1
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    VBA Code is copying a single cell only. Please spot the error for me.

    I have spent all day today to work out why my code is not working. I have got help from other site, but would keen to know why my own code is not working. I am sure the expert would be able to spot it. Although, I have three question on this code, for now I need to find why my code is not working.

    This code works

    Please Login or Register  to view this content.
    My code is not too different from the above, but only copies one row. Please spot the error for me.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: VBA Code is copying a single cell only. Please spot the error for me.

    When you are in Advanced reply, click on the paperclip to open the upload window.

    View Pic

    Please upload a sample workbook.
    Martin

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Code is copying a single cell only. Please spot the error for me.

    Thanks Martin! Please find attached
    If you run module 1, it copies the two rows with date values, but with my code(module 3) , it only copies one row.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Code is copying a single cell only. Please spot the error for me.

    Martin,
    I think the error may be on this line.
    Please Login or Register  to view this content.
    When I stepped over each cell, I can see the code picked up the right rows, but for some reason, it is overwriting the copied rows with the new one. As the are only two rows with dates value, the reason that I only see one row copied is because the code overwritten the previous row. So please help me correcting this line

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: VBA Code is copying a single cell only. Please spot the error for me.

    Hello AB33,

    When assigning a Range variable to a Range object, you must use the Set statement.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA Code is copying a single cell only. Please spot the error for me.

    You will also need to tweak the line you indicated in your post #4:
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Code is copying a single cell only. Please spot the error for me.

    Leigth and Rollis!
    Yes, I spotted the error my self, but it was too late here to post a repy.
    The set object was easy to spot from the errro message on VBA, but
    Please Login or Register  to view this content.
    was a bit tricky. It was overwriting all copied values in to A4, although, I want it to go in to next empty cell.
    Thanks for your help and suggestions! I valued any person's contribution as positive.

+ 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