+ Reply to Thread
Results 1 to 16 of 16

Find blank cell and replace based on criteria

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Find blank cell and replace based on criteria

    I currently use an IF formula to fill blank cells in my data set.
    Basically the formula checks for blank cells in columns C, D, E and F and fills them with the value in the row above or below IF the value column G is the same for each pair ( Column G always has data).

    Using a formula method I need to add another column to the data set for each of columns C, D, E and F.
    The data set has over 750,000 rows.

    I am looking to write a macro that will be do the same task WITHOUT adding any more columns to the data set.


    My formula:

    =IF(C100="",IF(G100=G99,C99,IF(G100=G101,C101,C100)))



    Is the macro as simple as selecting the range (say column C for example) and inserting my formula into the 'do' part of the macro??
    Last edited by anrichards22; 11-18-2012 at 01:53 AM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Find blank cell and replace based on criteria

    why do you need to add another column? If that formula is already there, Im sure it can be modified to suite?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    There is no formula in any of columns C, D , E or F...there is supposed to be data.

    I add another column in order to find blanks and replace with...

  4. #4
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Find blank cell and replace based on criteria

    Try this code and let me know if it works (obviously try it on test data, or a copy of your workbook first!!!):
    Please Login or Register  to view this content.
    - Moo

  5. #5
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Find blank cell and replace based on criteria

    One issue I know of with my VBA above is if there are two consecutive blank rows (columns C:F)... they will remain blank. My code only works if there is a single blank row at a time.

    - Moo

    * EDIT - It will work for two consecutive blank rows, as long as there are values to match in column G. =)
    Last edited by Moo the Dog; 11-18-2012 at 06:47 PM.

  6. #6
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    Will give it a try.

    Thanks Moo

  7. #7
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    Moo,

    Your code runs without errors but it does not fill the blanks!

  8. #8
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Find blank cell and replace based on criteria

    Hmmm.. it works for me. Do you have a sample worksheet you could upload? My test spreadsheet is attached... not sure how yours is set up though.

    - Moo
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    My data is formatted as a table, would that stop the macro from filling the blanks?

  10. #10
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Find blank cell and replace based on criteria

    Yes, that has a lot to do with it. Unfortunately, I don't know how to convert the code I wrote (which works just fine for normal ranges) into something that works on Tables in Excel.

    What I would recommend is to post a new thread, include my code above in the post if you want to (be sure to use code tags), as well as a small sample of your worksheet with the Table (remove any sensitive info if necessary) to see if someone else with more VBA knowledge is able to help accomplish what you need to do. Post in the same section (Programming/VBA/Macros) and use a title that includes something like "VBA to conditionally fill rows in a table."

    Sorry! I gave it my best shot.

    - Moo

  11. #11
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    No worries, thanks for your help Moo!

    Much Appreciated

    p.s. I reformatted as a range and your code worked beautifully!

  12. #12
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Find blank cell and replace based on criteria

    Hi anrichards22,

    Try this attached file and let me know is it meet ur requirement or not.
    Attached Files Attached Files

  13. #13
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Find blank cell and replace based on criteria

    Glad I could help, anrichards22... at least somewhat.

    - Moo

  14. #14
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    Quote Originally Posted by Naveed Raza View Post
    Hi anrichards22,

    Try this attached file and let me know is it meet ur requirement or not.

    I will give it try, Thanks Naveed

  15. #15
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Find blank cell and replace based on criteria

    Hi Naveed,

    I tried your code (after adapting it) and it does NOT work.

    I changed the code to this:

    Please Login or Register  to view this content.
    The blank cells are in the middle of my data (Columns T to AA) and the matching column is Column AC

    When I run your code it fills ALL the blank cells with whatever is in column AC.

  16. #16
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Find blank cell and replace based on criteria

    Yes it will fill that value only.

    If possible can u provide ur sample data so that i can make some small modification.

    Thanks - Naveed.

+ 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