+ Reply to Thread
Results 1 to 7 of 7

Using Vlookup to count the contents in a cell

  1. #1
    Registered User
    Join Date
    05-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    16

    Using Vlookup to count the contents in a cell

    I need to utilize vlookup as part of an excel formula and then count the entries in the cell of which the entries are separated by a space.

    For example, in one worksheet tab, the reference cell is 12345, using vlookup to search a range (say a1:c8), when a match is found in column a, I then want to sum the number of entries separated by a space in the corresponding cell in column c (of which the contents are: 574 625 895) and the desired return result would be 3.

    I know how to perform a similar test using an array formula to sum up the entire column as shown below but I am not sure how to tie in the vlookup so that I am only counting a single cell that I am requiring.

    {=SUM(IF(LEN(TRIM(M2:M2281))=0,0,LEN(TRIM(M2:M2281))-LEN(SUBSTITUTE(M2:M2281," ",""))+1))}
    Last edited by J Morrow; 02-24-2012 at 12:01 PM.

  2. #2
    Valued Forum Contributor mahju's Avatar
    Join Date
    11-27-2010
    Location
    Pakistan, Faisalabad
    MS-Off Ver
    Excel 2010 plus
    Posts
    730

    Re: Using Vlookup to count the contents in a cell

    Hi

    If your data range is c3:d5
    input is d7 then use this formula to count the numbers

    Please Login or Register  to view this content.

    See attached also
    Regards
    Attached Files Attached Files
    Mark the thread as solved if you are satisfied with the answer.


    In your first post under the thread tools.

    Mahju

  3. #3
    Registered User
    Join Date
    05-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using Vlookup to count the contents in a cell

    Thanks, however, I am receiving false positives; when the searched cell is blank, I receive a count of 1 when it should be 0. It would also be great if the formula could be explained to me so that I can understand what is taking place.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Using Vlookup to count the contents in a cell

    So are you counting the number of numbers in the cell or summing the numbers? If counting....

    =IF(VLOOKUP(X1,$A$1:$C$8,3,0)="","",LEN(VLOOKUP(X1,$A$1:$C$8,3,0))-LEN(SUBSTITUTE(VLOOKUP(X1,$A$1:$C$8,3,0)," ",""))+1)

    where X1 contains the input to search for..
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  5. #5
    Valued Forum Contributor mahju's Avatar
    Join Date
    11-27-2010
    Location
    Pakistan, Faisalabad
    MS-Off Ver
    Excel 2010 plus
    Posts
    730

    Re: Using Vlookup to count the contents in a cell

    Hi

    Use this

    Please Login or Register  to view this content.
    Explaination:

    First part of condition checks if the returned value is blank, place "0"
    if it is not blank then
    Count the total length of input value with len function (supose 10 with three spaces)

    Please Login or Register  to view this content.
    Then use substitute function to replace blanks (" ") with nothing (""). The length will be decreased (10-3=7) and get the length of new string

    Please Login or Register  to view this content.
    substrect first length from new length 10-7=3

    Add one so answer will be 4 (total pieces are always no. of dpaces +1)
    Regards

  6. #6
    Registered User
    Join Date
    05-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using Vlookup to count the contents in a cell

    I thank both mahju and NBVC for you responses. Both formulas work, I like the results better from the suggested formula from mahju simply that if the searched cell contains no data, the resulted outcome is 0. You both have answered my requirements and I thank you kindly.

  7. #7
    Valued Forum Contributor mahju's Avatar
    Join Date
    11-27-2010
    Location
    Pakistan, Faisalabad
    MS-Off Ver
    Excel 2010 plus
    Posts
    730

    Re: Using Vlookup to count the contents in a cell

    You are welcome

    Regards

+ 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