+ Reply to Thread
Results 1 to 7 of 7

vlookup syntax

Hybrid View

cmccabe vlookup syntax 05-24-2014, 10:08 AM
HaHoBe Re: vlookup syntax 05-24-2014, 10:26 AM
cmccabe Re: vlookup syntax 05-24-2014, 10:44 AM
HaHoBe Re: vlookup syntax 05-24-2014, 10:59 AM
cmccabe Re: vlookup syntax 05-24-2014, 11:20 AM
HaHoBe Re: vlookup syntax 05-24-2014, 12:37 PM
cmccabe Re: vlookup syntax 05-24-2014, 01:07 PM
  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    vlookup syntax

    Below is an attempt at a code that if the value in F2 is... then it does a vlookup in a shett named panel in a select range (G and H). Can someone please help me with the syntax? Thank you.

    '  Step 3 Add Inheritance
    i = Range("F" & Rows.Count).End(xlUp).Row
        For Each rngCell In Range("F2" & i)
            With ActiveSheet
            With .Range("C5:C" & lastrow)
    
            Select Case rngCell.Value
                            Case Is = "Comprensive Epilepsy"
                    With rngCell.Offset(0, 6)
                        .Formula = "=Index(Panel!H1:H70, Match(B5,panel!G1:G70,0))"
                      End With
                i = Range("F" & Rows.Count).End(xlUp).Row
                
                Select Case rngCell.Value
                            Case Is = "Marfan Disorder"
                    With rngCell.Offset(0, 6)
                        .Formula = "=Index(Panel!H25609:H25628, Match(B5,panel!G25609:G25628,0))"
                      End With
                End Select
                End With

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: vlookup syntax

    Hi, cmccabe,

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: vlookup syntax

    I uploaded a sample to box.net as it is too large to attach.

    https://app.box.com/s/mxui3162moqbi8z17ptk

    The desired worksheet has the Inheritance (column 3) filled in for the first 4 rows based on the gene in column 2. It looks up the gene name in the panel sheet and returns the value in the column next to the gene. Thanks.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: vlookup syntax

    Hi, cmccabe,

    I thought I knew a bit about guessing at what users may want but I´m lost without any descritpion as the code does not match the entries, and I´m not getting any idea of what you want to lookup, compare to what, return...

    I may add that a big workbook will not necessary be self-explanatory - at least in my case.

    Ciao,
    Holger

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: vlookup syntax

    Sorry for the confusion.

    There are 3 worksheets (panel, annovar, and desired)

    Panel: A-H (G and H are important)

    Annovar: A – AY (B and C are important)

    Desired: Match the value of B in annovar to column G in panel and return the value in Hin panel to column C in annovar

    So PPT1 is in G47 of panel and is autosomal recessive in column H off panel. In column B in annovar PPT1 is the first gene so the value is looked up in panel and the result in column H is returned to column C in annovar.

    I hope this helps and thanks.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: vlookup syntax

    Hi, cmccabe,

    Sub EF1013460()
    Dim rngCell As Range
    Dim wsLookUp As Worksheet
    
    Set wsLookUp = Sheets("panel")
    '  Step 3 Add Inheritance
    With Sheets("annovar")
      For Each rngCell In .Range("B5", .Range("B" & Rows.Count).End(xlUp))
        If WorksheetFunction.CountIf(wsLookUp.Range("G:G"), rngCell.Value) > 0 Then
          rngCell.Offset(0, 1).Value = WorksheetFunction.VLookup(rngCell.Value, wsLookUp.Range("G:H"), 2, 0)
        Else
          rngCell.Offset(0, 1).Value = "Item not found"
        End If
      Next rngCell
    End With
    Set wsLookUp = Nothing
    End Sub
    Ciao,
    Holger

  7. #7
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: vlookup syntax

    Thank you very much. Im not sure how it works, but the code is great. Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Incorrect Vlookup syntax
    By lordterrin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2014, 05:56 PM
  2. [SOLVED] Proper syntax for a VLOOKUP
    By Ascott82 in forum Excel General
    Replies: 3
    Last Post: 07-02-2012, 11:18 AM
  3. Macro VLookup Syntax problem
    By Peanuts890 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2011, 01:40 PM
  4. VLOOKUP syntax
    By salfonsi in forum Excel General
    Replies: 9
    Last Post: 02-13-2008, 06:02 PM
  5. [SOLVED] Vlookup syntax
    By SueJB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-14-2005, 01:05 PM

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