+ Reply to Thread
Results 1 to 12 of 12

Extracting the nth non-blank cell in a row

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    Lincoln, England
    MS-Off Ver
    Excel 365
    Posts
    9

    Smile Extracting the nth non-blank cell in a row

    Dear all

    I am a new user to the forum, and have already found your threads very useful!

    I was hoping that you could help with this problem:

    I have a spreadsheet with lots of students names (I am a teacher) and on each row there are the classes that they attend. Since each student does not attend every class, there are a lot of blanks in each row, as each class is listed in columns. I need a formula to extract the nth non-blank cell in a row, so I can extract the cells into a collection of columns based on each department in the school. For example, student A attends Art class 1, then there are 4 blanks and then they attend English class 2. Student B has a blank in their row, then they attend Art class 2, then 2 blanks as they attend English class 1. When all the data is extracted from each row, I should have a column for Art which is completely full, and below it should say 7Art1 (for student A), 7Art2 (for student B) etc. If I can extract the nth non-blank cell then I can tell the Art column to look for the 1st non-blank cell, the English column can look for the 2nd non-blank cell and so on...

    I hope this makes sense.

    Any help would be much appreciated!

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Extracting the nth non-blank cell in a row

    Hi arwright,

    welcome to the forum.

    Can you upload a sample workbook along with your expected results? Thanks.


    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  3. #3
    Registered User
    Join Date
    07-10-2013
    Location
    Lincoln, England
    MS-Off Ver
    Excel 365
    Posts
    9

    Re: Extracting the nth non-blank cell in a row

    Hi everyone

    Thanks for the quick reply!

    Please find the workbook attached. I have Office 365, so I use the latest version. I have provided the "before" raw data, and then an "after" tab which hows some of the data. I am the data analyst for my school and really need to pull together the horribly organised data I am supplied with from our database into a useable format. I would prefer a formula method if possible as I have not used VBA, but would love to learn more formula stuff!

    Your help is greatly appreciated!

    Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 365
    Posts
    2,406

    Re: Extracting the nth non-blank cell in a row

    Yeah Bro.... please upload your sample workbook

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extracting the nth non-blank cell in a row

    Maybe this one can be a start for solving your problem.

    Take a look at this file.

    I used the attached macro to get the result.
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  6. #6
    Registered User
    Join Date
    07-10-2013
    Location
    Lincoln, England
    MS-Off Ver
    Excel 365
    Posts
    9

    Smile Re: Extracting the nth non-blank cell in a row

    Hi

    Thanks for that. Ideally I would like one row per student though, with all their classes going horizontally (with no gaps).
    Is there a way to tweak your work to do it this way?

    Thanks again

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extracting the nth non-blank cell in a row

    So for all of these values you want an column?

    (I don't know if I can help you enough with it; but we gonna try it).

    AR
    EN
    FM
    FR
    GG
    GS
    HI
    IT
    MA
    MU
    PE
    RE
    SC
    TE
    ES
    SB


    2nd question about this item

    and what about duplicated values: like this below

    A GG\232 7Ge1 GG
    A GG\373 7Ge1 GG

    How should that be stored in your file?
    Last edited by oeldere; 07-11-2013 at 05:15 PM.

  8. #8
    Registered User
    Join Date
    07-10-2013
    Location
    Lincoln, England
    MS-Off Ver
    Excel 365
    Posts
    9

    Re: Extracting the nth non-blank cell in a row

    Hi

    Yes please - each of the values represents the code for a subject e.g. MA = Mathematics (sorry, I should have said this).

    Could duplicates be removed if possible?

    thanks again

  9. #9
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extracting the nth non-blank cell in a row

    Could duplicates be removed if possible?
    A GG\232 7Ge1 GG
    A GG\373 7Ge1 GG

    above example counts als duplicated? (or not)?

  10. #10
    Registered User
    Join Date
    07-10-2013
    Location
    Lincoln, England
    MS-Off Ver
    Excel 365
    Posts
    9

    Re: Extracting the nth non-blank cell in a row

    Hi

    A GG\232 7Ge1 GG
    A GG\373 7Ge1 GG

    Yes they do count as duplicates - they both mean Year 7 Geography class 1

    Thanks again - it is greatly appreciated!

  11. #11
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extracting the nth non-blank cell in a row

    I will ask other forummember to help us with this problem.

    I post the link afterwards. (#249)

    http://www.excelforum.com/the-water-...00#post3320500
    Last edited by oeldere; 07-12-2013 at 01:13 PM.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extracting the nth non-blank cell in a row

    This is an array formula, it is designed to find each non-blank cell for each student and list them in order across their row on AFTER sheet. This formula is entered into B2:

    =IFERROR(INDEX(OFFSET(sheet2!$A$1,MATCH($A2,sheet2!$A$2:$A$14,0),1,,200),SMALL(IF(OFFSET(sheet2!$A$1,MATCH($A2,sheet2!$A$2:$A$14,0),1,,200)<>"",COLUMN(OFFSET(sheet2!$A$1,MATCH($A2,sheet2!$A$2:$A$14,0),1,,200))-1,""),COLUMNS($B$1:B$1))), "")

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    Once that is entered correctly and the first correct value appears, copy that cell down, then across to the right as far as needed.


    I've entered this formula across through columnY, enough for 24 classes. I know this doesn't organize by class type, but this gives you your student's classes. You could use this table as a second refernce to build a class type schedule, as separate project.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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