+ Reply to Thread
Results 1 to 11 of 11

get cell value if vlookup returns a specific data

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    59

    get cell value if vlookup returns a specific data

    Hi all,
    I am setting up a schedule and kinda hit a bump.
    1. In sheet 1 I have the actual schedule. If someone is working "AM", he'll look for his name and make the change in the appropriate date column.
    2. In sheet 2 I want the data to be organized by date and if the co-worker is working either "AM" or "PM". I am not sure what formula to use to get the name from sheet 1.

    Any help would be much appreciated. Test.xls

    Thanks,
    Amar.

  2. #2
    Registered User
    Join Date
    06-07-2013
    Location
    四川自贡
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: get cell value if vlookup returns a specific data

    Is the result your need?Do you need the attachment?
    Sub 查找人名()
       Dim arr, brr, crr(100, 2)
       Dim num1&, num2&
       Dim i&, j&, k&, i1&, j1&
       Dim a$, b$
           num1 = Sheet1.Range("c65536").End(xlUp).Row
           num2 = Sheet1.Range("aa4").End(xlToLeft).Column
           arr = Sheet1.Range(Sheet1.Cells(4, 3), Sheet1.Cells(num1, num2))
           num1 = Sheet2.Range("b65536").End(xlUp).Row
           num2 = Sheet2.Range("aa2").End(xlToLeft).Column
           Sheet2.Range(Sheet2.Cells(3, 3), Sheet2.Cells(num1, num2)).ClearContents
           brr = Sheet2.Range(Sheet2.Cells(2, 2), Sheet2.Cells(num1, num2))
           k = 0
              For j = 2 To UBound(brr, 2)
                  For i = 2 To UBound(brr)
                     For j1 = 2 To UBound(arr, 2)
                         If brr(i, 1) = arr(1, j1) Then
                            For i1 = 2 To UBound(arr)
                                If arr(i1, j1) = brr(1, j) Then
                                   brr(i, j) = arr(i1, 1) & brr(i, j)
                                End If
                            Next i1
                         End If
                      Next j1
                    Next i
                Next j
             Sheet2.Range(Sheet2.Cells(2, 2), Sheet2.Cells(num1, num2)) = brr
    End Sub

  3. #3
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: get cell value if vlookup returns a specific data

    Hi

    I think you will need to change your inner loop to test for Upper case. I would also suggest splitting the names with a space to make the result more readable.

    For i1 = 2 To UBound(arr)
                                If UCase(arr(i1, j1)) = UCase(brr(1, j)) Then
                                   brr(i, j) = arr(i1, 1) & " " & brr(i, j)
                                End If
                            Next i1
    The OP also needs to add column E to Sheet2 with a heading of MID to correspond with data on Sheet1
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  4. #4
    Registered User
    Join Date
    06-07-2013
    Location
    四川自贡
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: get cell value if vlookup returns a specific data

    You are right,,I don't know how to use “UCase”,I just Modify the content “AM” ->“am”

  5. #5
    Registered User
    Join Date
    06-07-2013
    Location
    四川自贡
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: get cell value if vlookup returns a specific data

    You are right,,I don't know how to use “UCase”,I just Modify the content “AM” ->“am”

  6. #6
    Registered User
    Join Date
    06-07-2013
    Location
    四川自贡
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: get cell value if vlookup returns a specific data

    thank you Roger Govier
    The modified
    Sub 查找人名()
       Dim arr, brr, crr(100, 2)
       Dim num1&, num2&
       Dim i&, j&, k&, i1&, j1&
       Dim a$, b$
           num1 = Sheet1.Range("c65536").End(xlUp).Row
           num2 = Sheet1.Range("aa4").End(xlToLeft).Column
           arr = Sheet1.Range(Sheet1.Cells(4, 3), Sheet1.Cells(num1, num2))
           num1 = Sheet2.Range("b65536").End(xlUp).Row
           num2 = Sheet2.Range("aa2").End(xlToLeft).Column
           Sheet2.Range(Sheet2.Cells(3, 3), Sheet2.Cells(num1, num2)).ClearContents
           brr = Sheet2.Range(Sheet2.Cells(2, 2), Sheet2.Cells(num1, num2))
           k = 0
              For j = 2 To UBound(brr, 2)
                  For i = 2 To UBound(brr)
                     For j1 = 2 To UBound(arr, 2)
                         If UCase(brr(i, 1)) = UCase(arr(1, j1)) Then
                            For i1 = 2 To UBound(arr)
                                If UCase(arr(i1, j1)) = UCase(brr(1, j)) Then
                                   brr(i, j) = arr(i1, 1) & brr(i, j)
                                End If
                            Next i1
                         End If
                      Next j1
                    Next i
                Next j
             Sheet2.Range(Sheet2.Cells(2, 2), Sheet2.Cells(num1, num2)) = brr
    End Sub

  7. #7
    Registered User
    Join Date
    08-30-2012
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: get cell value if vlookup returns a specific data

    Hey guys,
    After lots of trial and error, I finally figured out the formula. I didn't use vlookup. Here it is:

    =IFERROR(INDEX(Sheet1!$B$4:$B$20,MATCH(Sheet2!$A$6,Sheet1!C$4:C$20,0)),"")
    For those who need it, here's an explanation of what it does.

    1. Cells B4:B20 in sheet1, contains the names of my co-workers
    2. Cell A6 in sheet 2 contains "AM".
    3. Cells C4:C20 in sheet 1, is the row that the formula needs to "look in" and it has a date in cell C4.

    If someone is working "AM" on 12/06/2013, the formula will find the corresponding name in cell B4:20 and drop it in sheet 2.

    Thanks for your response.

    Regards,
    Amar.

  8. #8
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: get cell value if vlookup returns a specific data

    Hi

    And how, exactly, is that supposed to refer to what you originally posted??
    There is no similarity between this formula and the information you posted on Sheet Test.xls

  9. #9
    Registered User
    Join Date
    08-30-2012
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: get cell value if vlookup returns a specific data

    Hi,
    I mentioned that I had to use a combination of formulas and do a lot of research.
    I'm not sure how it is different from what I posted/requested. I've attached a sample spreadsheet.

    Regards.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: get cell value if vlookup returns a specific data

    Hi

    Well for a start,
    1. your original file had nothing whatsoever in column A of either sheet.
    2. The file you have just posted, has column A on both sheets hidden - why do you expect those trying to help you to have to look at your sheet and decide they need to unhide columns.
    3. Your formula does not produce any result whatsoever.
    3. Your second Workbook posted, contains no data whatsoever.
    4. If one copies in your data from your original posting, then the result of your formula is Name 3 in every cell from C3 tp C9, and nothing elsewhere

    If you do want help
    a). Post a sensible question with a full explanation of what you have and what you expect the result to be.
    b). Don't then change your definitions, and, use hidden columns
    c). acknowledge the help given by those who have taken considerable time to write code for you - e.g Someone from China - and expalin why their solution doesn't match what you are looking for (if it doesn't)
    d). don't just post back saying I have solved the problem with a simple formula, when you clearly haven't.

    I for one, will definitely avoid any request from you in the future.

  11. #11
    Registered User
    Join Date
    08-30-2012
    Location
    Ottawa
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: get cell value if vlookup returns a specific data

    Just chill man. I did thank them for their input. I don't know why you're making such a fuss?!
    I forgot to unhide it. it happens. Human error!
    No data in my second workbook and didn't solve the problem? What are you talking about?
    I was only looking for help and as I was waiting for an answer, I was also trying to solve my problem... which I did.
    I don't want you to think that I'm a "cocky" user, but if you don't want to help me, then so be it.

    Have a great day.

+ 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