+ Reply to Thread
Results 1 to 11 of 11

Issue with VB code which duplicates data to below records.

  1. #1
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Issue with VB code which duplicates data to below records.

    I have the following code which duplicates the data in either column E or H (depending on which cell is active) to all the empty cells below as far as the last record (it checks for the last cell with data in the G column to find the last record). The formula works flawlessly as long as there are two or more records. If there is only one record then it is unable to find the last row, as it duplicates the data to every empty cell from Columns A to AD, and rows 1 to 944.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Issue with VB code which duplicates data to below records.

    your code works on my test sheet, attach please a sample file with notes
    If solved remember to mark Thread as solved

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Issue with VB code which duplicates data to below records.

    Did not try it, but how about adding

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Issue with VB code which duplicates data to below records.

    Dave is this what your thinking:
    Please Login or Register  to view this content.
    I tried that but it didnt change anything.

    I have attached my workbook. Go to the last row (326 on ReturnData sheet). If you select H326 and press the Duplicate Data Macro at the top it correctly copies the data to the two empty cells below. However if you select E327 and press Data Duplicate, being only one cell below to copy to, it copies it to a whole bunch of cells.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Issue with VB code which duplicates data to below records.

    SpecialCells(xlCellTypeBlanks) does not work in a single cell, try this code
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Issue with VB code which duplicates data to below records.

    Thanks patel, that fixed it.

  7. #7
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Issue with VB code which duplicates data to below records.

    Patel I have just come across a bug with this code. If I select a cell on the last row of data and hit data duplicate it correctly duplicates that data to the row below, and if I select say a cell a few rows above the last row (and all the cells below it already contain data) then I correctly get an error message. However If I select the second to last row and hit Data Duplicate it copies the data to every blank cell on the workbook. How can I prevent this?
    I have attached my workbook.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Issue with VB code which duplicates data to below records.

    I'm sorry but I don't remember, tell me what sheet, what code,

  9. #9
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Issue with VB code which duplicates data to below records.

    Its on the ReturnData sheet, and this is the code:

    Please Login or Register  to view this content.
    The button Duplicate Data at the top runs the module.

  10. #10
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Issue with VB code which duplicates data to below records.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Issue with VB code which duplicates data to below records.

    Awesome, that fixed it. Thank you.

+ 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. [SOLVED] Code to compare data in 2 sheets and delete duplicates
    By amar05 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-13-2013, 03:24 PM
  2. Replies: 5
    Last Post: 04-30-2013, 07:42 PM
  3. [SOLVED] Extract unique records from data set with duplicates
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 11:17 AM
  4. Find records that DON'T have duplicates
    By struct in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-30-2011, 11:58 AM
  5. Removing all records thats are duplicates
    By ClikClak in forum Excel General
    Replies: 4
    Last Post: 05-17-2010, 11:05 AM

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