+ Reply to Thread
Results 1 to 13 of 13

Copy cell value above to cells below if blanks

  1. #1
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Copy cell value above to cells below if blanks

    Hey Everyone,

    There is an issue im running into here and I cant figure it out.

    I have a program to take account numbers and separate them into single rows, once they populate into the new rows I want to get the blanks to fill with the information from the account in the rows adjacent to them. If I use the last row method the macro returns ref, but if I use a set number of rows this does not occur.

    Here is my current code.

    Please Login or Register  to view this content.
    So it breaks column A into individual rows, and then scans for blanks, it should take the information from the cell above, and then copy that into the cell below for columns b-f (G-R) do not need to fill blanks at all they can be left as is.

    The problem is the worksheet can change length so I tried to add the last row, now I get REF! instead of the name from the cell above on any instance where there are multiple splits
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    Hi fawkes... first:

    Please Login or Register  to view this content.
    is a bit redundant... lastrow has been calculated in the first, and then the calculation is done a second time in the second line. Just use (to replace the second line, leave the first):
    Please Login or Register  to view this content.
    Totally separate, lets for example assume that lastrow is 52 (random example). This line:

    Please Login or Register  to view this content.
    means you are putting together A2 and lastrow, so it is the same as saying Range("A252"). Maybe you meant Range("A2:A" & lastrow)? That would make the search for blanks in the range A2 to the last row in column A.
    Or, if you are searching B to G, from row 2 to the last one then
    Please Login or Register  to view this content.
    Last edited by Arkadi; 02-10-2017 at 03:04 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: Copy cell value above to cells below if blanks

    as always arkadi you are correct, and I missed some super simple things...

    I am however getting an error on the last line where the remove duplicates takes place. it needs to go through column a and delete any rows that have duplicates. so if it is a duplicate acct number it should delete that row keeping only one of every account number.

    Here is my adjusted code.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    Range.Removeduplicates... the range is all the range (all columns and rows) that need to be scanned and removed, the columns argument is the column so find duplicates in. Since your range is only column A, there is no column 2, and thus the error. What you need (I believe) is:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: Copy cell value above to cells below if blanks

    Im starting to scratch my head here, there are three sheets I use this on for one it works all the way down no problem and for two it completes the macro but it stop filling the balnk cells half way down... im confused. maybe the equation is the problem?

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    Not at a pc now.... Lemme get back to you...all have data all the way down colum a right? Last row is based on that column.

  7. #7
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: Copy cell value above to cells below if blanks

    Yes column a is 100% populated. problem is some people submit with the account numbers like this ######/ ######/ ###### so I wrote this to split them into their own rows. but now after switch to the lastrow methos so it would be able to handle any new additions, it is failing on the copy portion.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    Oooh... Now i see... So at start u get last row but then you are making new rows.... After "next rindex" you need to re-calculate lastrow.... Just repeat lastrow=..... After your rindex loop finishes

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    Lastrow is set at start and unless u update it, it thinks lastrow is still the old last row

  10. #10
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: Copy cell value above to cells below if blanks

    That makes a lot of sense smh... Thank you again

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    You are welcome Fawkes_
    I assume that resolved your issue?
    Thanks for marking the thread as solved!

  12. #12
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: Copy cell value above to cells below if blanks

    Hey Arkadi, I had a question about that big project you helped me with, Is it alright if I inbox you?

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy cell value above to cells below if blanks

    yeah sure, go ahead

+ 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] Find non-blanks cells and copy to another worksheet
    By A440 in forum Excel General
    Replies: 4
    Last Post: 10-04-2016, 07:57 AM
  2. [SOLVED] VBA Macros to Look for blanks cells and copy data
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2013, 02:26 AM
  3. [SOLVED] Copy cells from one worksheet to another while skipping blanks
    By gawk1980 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-23-2013, 05:02 PM
  4. Replies: 1
    Last Post: 10-24-2012, 01:21 PM
  5. copy cells ignoring blanks
    By twofootgiant in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2011, 10:35 AM
  6. copy cells but miss blanks
    By wonderdunder in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-29-2010, 09:50 AM
  7. Copy cells to adjacent column, removing blanks
    By jbitluk in forum Excel General
    Replies: 8
    Last Post: 12-11-2009, 03:14 PM

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