+ Reply to Thread
Results 1 to 31 of 31

Testing for Blank Cells

Hybrid View

  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Question Testing for Blank Cells

    I am trying to write an Excel formula to test if there is data in pairs of cells and if there is I want to copy the entire record to another Excel spreadsheet. Example: if there is data in row 1, column A and data in row 1, Column C or row 1 column D, then copy this record to another spreadsheet; if there is data in row 1 column B and data in column C or column, then copy this record to another spreadsheet. Since there is no data in row 4, column C or column D, this row would not be copied. Row 1, row 2, row 3, and row 7 would be copied to another spreadsheet. The data can be numeric or alpha numeric. I tried using the ISBLANK statement and can't seem to get this to work properly. Any suggestions?


         A       B        C        D
    R1  234A    N333     4T41     7657
    R2  11C2              321     3T27
    R3          L954      989
    R4                   56D1    297-1
    R5  87E3    P199 
    R6  D992
    R7  Z222             3391
    I
    Last edited by shg; 10-02-2009 at 11:09 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Testing for Blank Cells

    Post the code you have so far -- in code tags, please.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Testing for Blank Cells

    Shg,
    I am not an Excel expert by any means, but here's what I've tried.

    =IF(OR(ISBLANK(A1),ISBLANK(C1)),"",M10),(OR(ISBLANK(A1),ISBLANK(D1)),"",M10),(OR(ISBLANK(B1),ISBLANK(C1)),"",M10),(OR(ISBLANK(B1),ISBLANK(D1)),"",M10),

    Basically there are 4 combinations that I'm trying to test. I'm using M10 to represent the record that I wish to copy to another spreadsheet. Below is what the spreadsheet looks like; it got disoriented in my original posting.


    --------A -------B ------C ------D
    R1 ---234A--- N333---4T41 ---7657
    R2 ---11C2 ---321 ----3T27
    R3 -----------L954 -------------989
    R4 -56D1-----297-1-----------
    R5 --------------------87E3 ----P199
    R6- D992-------------------------
    R7 -Z222------------------------3391

    Thanks!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Testing for Blank Cells

    In E1 and copy down,

    =COUNTA(A1:B1)*COUNTA(C1:D1)

    The cells with non-zero results are the ones to be copied. Does that work for you?

  5. #5
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Testing for Blank Cells

    I'm don't think this works. The possible combinations to copy the complete record as as follows: A1 and C1 combined must not be blank; or A1 and D1 combined must not be blank; or B1 and C1 combined must not be blank; or B1 and D1 combined must not be blank. If one cell of any of the four combinations is blank, then I do not want to copy the record. Thanks!

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Testing for Blank Cells

    This:
    A1 and C1 combined must not be blank; or
    A1 and D1 combined must not be blank; or
    B1 and C1 combined must not be blank; or
    B1 and D1 combined must not be blank.
    ... does not gibe with this:
    if there is data in row 1, column A and data in row 1, Column C or row 1 column D, then copy ...
    if there is data in row 1 column B and data in column C or column [D], then copy ...
    Either is possible; which do you want?
    Last edited by shg; 10-02-2009 at 12:37 PM.

  7. #7
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Testing for Blank Cells

    Shg,

    I need to do both. Thanks

  8. #8
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Testing for Blank Cells

    Shg,

    Please see my first posting. The sample data is correct as posted. When I initially posted this, it was disoriented. Row 1, copy; row 2, copy; row 3, copy; row 4, no copy; row 5, no copy; row 6, no copy, row 7, copy.

    From my perspective, there are 4 possible "2 cell" combinations that need to be tested if blank or not. If one cell of the 2 cell combination is blank, this would result in a no copy. Thanks for your help!

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Testing for Blank Cells

    We've now come full circle. Here's the original formula applied to that data:

          --A-- -B-- -C-- --D-- E --------------------F--------------------
      1    234A N333 4T41  7657 4 E1 and down: =COUNTA(A1:B1)*COUNTA(C1:D1)
      2    11C2       321  3T27 2                                          
      3         L954  989       1                                          
      4              56D1 297-1 0                                          
      5   87000 P199            0                                          
      6    D992                 0                                          
      7    Z222      3391       1
    Rows 1, 2, 3, & 7 are non-zero.

  10. #10
    Registered User
    Join Date
    09-17-2009
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    9

    Smile Re: Testing for Blank Cells

    Okay...

    It seems to me, you will have to actually write a macro to paste each individual row into a new workbook or worksheet. I'll try to mess with how to put that all together over some time...but try to get it yourself as well...

    So far...I think this is what you'll need to get started...

    =IF(COUNTA(A1),IF(COUNTA(C1),"2",IF(COUNTA(D1),"2","1")),IF(COUNTA(B1),IF(COUNTA(C1),"2",IF(COUNTA(D1),"2","0")),"0"))

    Paste that at the end of 1st row (E1, for example), and then drag it down. That will count whether there are values in A1 & C1, A1 & D1, B1 & C1, or B1 & D1...in that order. If any are true, they return "2". Once you have the "2", you will be able to write a macro to extract rows with a "2" in column E:E.

    I hope that leads you in the right direction...

  11. #11
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Testing for Blank Cells

    Shg,

    Thanks for your help. I have a couple additional questions. Sorry for not being Excel savy.

    Your formula for the testing the data does work. Our spreadsheet has 18 columns of data and over 12,000 rows of data. I wish to use your formula to test each row of data and when there is a match copy the entire row to another spreadsheet. How can I set up you formula to read each row without having to define the last row of data? Also, is there a way to copy each row of data as a whole row rather than on a cell by cell basis?

    Thanks

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Testing for Blank Cells

    Post a sanitized example of the data, but having representative contents?

    Also, does the data get copied to another sheet in the same workbook, and if so, does it replace what's already there? Or another workbook?

    All the particulars, please ...

  13. #13
    Registered User
    Join Date
    10-01-2009
    Location
    Santa Maria, CA
    MS-Off Ver
    Excel 2003
    Posts
    30

    Red face Re: Testing for Blank Cells

    Shg,

    Thanks for the formula. I'm sorry that I didn't understand the first time around. I do have additional questions. We have a spreadsheet that being used to collect data. It presently has over 12,000 rows, 18 columns wide. I wish to use your formula to test each row and it there is a match, copy the row to another spreadsheet. How can I set up the formula to to read the 12,000 rows without naming the final row so that if more rows are added to the formula does not have to be modified? Also, is there an faster way to copy the entire row when there is a match rather than each cell of the row?

    Thanks!

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Testing for Blank Cells

    I'll help with that. Would you please respond to my prior post?

+ 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