Consulting

Results 1 to 9 of 9

Thread: VLOOKUP Not Updating when Data Repeated

  1. #1

    VLOOKUP Not Updating when Data Repeated

    Hello!
    I have a quote tool that uses VLOOKUP formulas. I use userforms to gather data and upload it to an excel sheet. I have noticed that the formula works the first time I input a product. However, if I enter the same product again, the formula seems to only recognize the first instance even though the second instance shows up within the VLOOKUP range. Is there an update function or something that is needed to find these second and third instances of the same product?

    Thank you so much for your help!!

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I think that the way VLookup works -- only finds the first

    You can try .Find or .Filter if you want them all


    Something like this

    Option Explicit
    
    
    Sub drv()
        Dim r As Range
    
    
        Set r = FilteredData(ActiveSheet.Cells(1, 1).CurrentRegion, 1, "AAA")
        If Not r Is Nothing Then r.Interior.Color = vbRed
    
    
        Set r = FilteredData(ActiveSheet.Cells(1, 1).CurrentRegion, 1, "ddd")
        If Not r Is Nothing Then r.Interior.Color = vbGreen
    
    
    End Sub
    
    
    Function FilteredData(r As Range, c As Long, v As Variant) As Range
    
    
        On Error GoTo NiceExit
    
    
        With r
            If .Parent.FilterMode Then .AutoFilter
            
            .AutoFilter
            .AutoFilter Field:=c, Criteria1:=v
                
            'hide header row
            .Rows(1).EntireRow.Hidden = True
            Set FilteredData = r.SpecialCells(xlCellTypeVisible)
            .Rows(1).EntireRow.Hidden = False
        
            .AutoFilter
        End With
    
    
        Exit Function
    
    
    NiceExit:
        Set FilteredData = Nothing
    
    
    End Function
    Attached Files Attached Files
    Last edited by Paul_Hossler; 12-09-2019 at 04:11 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For a formula-based solution, see: http://www.techsupportforum.com/foru...ml#post2567119
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Thank you for both responses. I was actually able to take something from both and solve a different issues I was having! However, in this case, I need to clarify what I am doing. See example below:

    Sheet 1
    A B
    TLC-03 10
    TLC-03 15
    TLC-03 20

    Sheet 2, Cell A2 needs to calculate the number of TLC-03 parts are ordered. In this case the total is 45. With VLOOKUP, my current cell A2 only calculates 10.

    I hope that helps clarify and so sorry that my first question wasn't so clear.

    Thank you in advance!!

  5. #5
    NOticed the data didn't transfer over well...
    Column A is the part, column B is the qty.

  6. #6
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    I can only guess without the attachment.
    I think it's better for you to use SUMIF here.

    --Okami

  7. #7
    I will try a few sumif functions and see if I can get that to work. Thank you!

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For example:
    =SUMIF(Sheet1!A:A,"TLC-03",Sheet1!B:B)
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    SUMIF was the way to go!

    Thanks all!!

Posting Permissions

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