+ Reply to Thread
Results 1 to 13 of 13

Fill up the current cell with the value of the previous cell is the current cell is empty

  1. #1
    Registered User
    Join Date
    11-02-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    21

    Question Fill up the current cell with the value of the previous cell is the current cell is empty

    Hi,

    I wrote the code below. It didn't given an error but wouldn't work either. My goal is to fill up the activecell with the value of the previous cell if the activecell is empty. For example if A2 is banana, A3 is apple and A4 is blank, then the value of A4 should be apple. This process will continue until the lastrow in variable lRow2. I was thining of using do-while-loop but i thought it would be simple to use for-loop.

    Please Login or Register  to view this content.

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

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Most likely the cells are not empty but blank null string.

    Please Login or Register  to view this content.
    Last edited by AB33; 12-03-2013 at 05:48 AM.

  3. #3
    Forum Contributor
    Join Date
    11-21-2013
    Location
    zimbabwe
    MS-Off Ver
    Excel 2003
    Posts
    124

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Select cell A2 (first cell in data range) then run macro as below
    Please Login or Register  to view this content.

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

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Please Login or Register  to view this content.
    Counts the number of non empty cells which is not the same as you want to loop down until the last non empty cell in a column D.

    Please Login or Register  to view this content.
    Should do

  5. #5
    Registered User
    Join Date
    11-02-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    i used a message box to know the value of lrow2 and it is just fine. I've revised my code (below) but still wouldnt work



    Please Login or Register  to view this content.
    And here's my data:Attachment 281717


    Quote Originally Posted by AB33 View Post
    Please Login or Register  to view this content.
    Counts the number of non empty cells which is not the same as you want to loop down until the last non empty cell in a column D.

    Please Login or Register  to view this content.
    Should do

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

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Please Login or Register  to view this content.
    looks at the last row minus in column D, while your other lines loop through column A

    Please Login or Register  to view this content.
    There is a problem with the attachment. I am unable to down load it.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Hi, danex,

    maybe try
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Registered User
    Join Date
    11-02-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    i used column only to find the last row with value - just the row number to bused in looping. The attachment is just an image.

    Quote Originally Posted by AB33 View Post
    Please Login or Register  to view this content.
    looks at the last row minus in column D, while your other lines loop through column A

    Please Login or Register  to view this content.
    There is a problem with the attachment. I am unable to down load it.

  9. #9
    Registered User
    Join Date
    11-02-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Thanks. But I figured out I should have used for-each-in a range. I had no success with do-while and for-1 to n.
    Quote Originally Posted by HaHoBe View Post
    Hi, danex,

    maybe try
    Please Login or Register  to view this content.
    Ciao,
    Holger

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

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    The attachment is just an image.
    Can not even see the image.
    Please refer to my post #2.
    If you had attached a sample, It would have been resolved two days. We now are on the 3rd day.

  11. #11
    Registered User
    Join Date
    11-02-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Here's the image data.jpg

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

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    A Picture is not much help. You can not test a picture.
    To test if column A cells are blank, with out a code:
    CRTL plus G will take you to "go special" then click blank and see if any find any cells highlighted.

  13. #13
    Registered User
    Join Date
    11-02-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Fill up the current cell with the value of the previous cell is the current cell is em

    Here is the spreadsheet via google doc https://drive.google.com/file/d/0B1k...it?usp=sharing

+ 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] Auto-fill the current date if the previous row was empty
    By lesoies in forum Excel General
    Replies: 5
    Last Post: 09-22-2012, 11:44 AM
  2. Format the previous cell based on the value of the current cell.
    By IamHarish in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2011, 05:59 PM
  3. Excel 2007 : Format previous cell based on current cell
    By IamHarish in forum Excel General
    Replies: 5
    Last Post: 12-05-2011, 06:06 PM
  4. Replies: 3
    Last Post: 11-17-2010, 04:28 AM
  5. [SOLVED] formula, move to previous cell when the current cell=0 or empty
    By osama amer in forum Excel General
    Replies: 0
    Last Post: 05-29-2006, 07:25 AM

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