Results 1 to 13 of 13

Thread: [RESOLVED] Getting Grade wise names

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    22

    Resolved [RESOLVED] Getting Grade wise names

    Hi All,

    I have an excel sheet attached herewith..

    I want a formula that gives me all the names whose grade is "C"..

    Can anyone please help?

    Thanks in advance...
    Attached Files Attached Files
    Last edited by abhi51082; Dec 16th, 2009 at 09:34 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting Grade wise names

    that gives me all the names
    to do what?
    you can use countif to count the number of names with a specific grade
    or you could probably use a formula array to put all those name into other cells
    you could use conditional formatting to change the colours of the cells for each grade
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    22

    Re: Getting Grade wise names

    Hi Westconn,

    What i want is, I have 2 columns, 1 column is of names of individuals and 2nd column is of Grade. Now in a differently located cell if i write "C" then below that should appear all the names from Column 1 whose adjecent cell in 2nd column shows "C".

    I tried using VLookUp formula but it is not giving me the correct answer.

    I am not good with array... Could you please help me for that...

    Just to tell you that i have 2000 or more rows with such data...

    Thanks in advance...

  4. #4
    Member
    Join Date
    Nov 2009
    Posts
    35

    Re: Getting Grade wise names

    If you are happy with doing it directly on the data (and not a different location as you say) then just use AutoFilter. Have a look at AutoFilter in the Help file.

    -Terry

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting Grade wise names

    i could create a custom worksheet function to do what you want, but better to use inbuilt functions or methods wherever possible
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    22

    Re: Getting Grade wise names

    TerryTee...
    Auto filter is good and i have also used it but it would not give me an answer in a different column...

    Westconn1...
    I am not able to find out any inbuilt functions or method for sorting out my problem...
    If you have anything which can help me or any function or method which can solve such query then please state the same...

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Getting Grade wise names

    Abhi

    Howz A'bad doing without me?

    Further to our conversation, it is not possible to do this with a native function. You will have to use VBA like Pete suggested. Instead of a function you could write a code for the worksheet selection change event which will capture the letter that you will type and then search for the names meeting that criteria and finally display them in the respective column....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting Grade wise names

    afaik it is not possible to update any cells from within a worksheet function except the calling cell

    i did get this to work reasonably well (just forgot to post it)
    vb Code:
    1. 'in a module
    2. Public myarr() As Variant
    3.  
    4. Function getgrades(r As Range, grade As String) As String
    5. Dim res() As Variant
    6.  
    7. i = 0
    8. For Each c In r
    9.     If c = grade Then ReDim Preserve res(i): res(i) = c.Offset(, 1): i = i + 1
    10.     If c = grade Then mystr = mystr & vbLf & c.Offset(, 1)
    11. Next
    12. getgrades = ""
    13. myarr = res
    14. End Function
    15.  
    16. ' in the worksheet
    17. Private Sub Worksheet_Change(ByVal Target As Range)
    18. If Target.Cells.Count > 1 Then Exit Sub
    19. If InStr(Target.Formula, "getgrades") = 0 Then Exit Sub
    20. On Error Resume Next
    21. Range(Target.Offset(1), Target.Offset(UBound(myarr) + 1)) = Application.WorksheetFunction.Transpose(myarr)
    22. End Sub
    this puts the names into the cells below the formula
    put formual like =getgrades(C8:C17,"C") change range or grade to suit
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    22

    Re: Getting Grade wise names

    Hi Westconn,

    sorry mate but the code which you uploaded is not working..

    please upload the file which you have made for writing this code and let me know how have you done the same..

    abhi

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting Grade wise names

    i never saved it, but as the code is here it should be easy enough to do again

    edit: don't know why there is error in the code, as i did test it just change the code in the function, the rest stays the same
    vb Code:
    1. Function getgrades(r As Range, grade As String) As String
    2. Dim res() As Variant
    3. i = 0
    4. For Each c In r
    5.     If c.Offset(, 1) = grade Then ReDim Preserve res(i): res(i) = c: i = i + 1
    6. Next
    7. getgrades = ""
    8. myarr = res
    9. End Function
    Last edited by westconn1; Dec 29th, 2009 at 03:56 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    22

    Re: Getting Grade wise names

    Hi Westconn,

    sorry mate, once again the code which you uploaded is not working..

    so only i am telling you to please upload the file which you have made for writing this code and let me know how have you done the same..

    abhi

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Getting Grade wise names

    here it is
    Attached Files Attached Files
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    22

    Thumbs up Re: Getting Grade wise names

    Thanks mate...its working...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width