+ Reply to Thread
Results 1 to 5 of 5

Macro using Vlookup

Hybrid View

  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro using Vlookup

    Take a look here and see if you get some ideas.

    http://www.contextures.com/Excel-VBA...Box-Lists.html
    HTH
    Regards, Jeff

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro using Vlookup

    I was doing some more playing around with this and came up with some code which I believe may work for you.

    I'm guessing you are trying to return the total accumulated amount for either James or John? If this is the case then it seems you would want to use a Sumif function versus the Vlookup which will only return one result, not a total.

    So here a two pieces of code to use.

    The first uses advanced filter to make a unique list for the combobox and the second will populate textbox1 on change of combobox1. Unique list will be created in column L.

    I figured using the code provided you could probably figure out how to add to the code for the second textbox.

    This is just one way to do it, but I'm sure if you poked around more you could find others. I hope this helps.

    Private Sub UserForm_Initialize()
        With Sheet1
            .Range(.Range("E3"), .Range("E" & .Rows.Count).End(xlUp)) _
            .AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("L3"), Unique:=True
            ComboBox1.List = .Range(.Cells(4, 12), .Cells(.Rows.Count, 12).End(xlUp)).Value
        End With
        Me.ComboBox1.SetFocus
    End Sub
    Private Sub ComboBox1_Change()
        Dim CL As Range
        Dim AA As Range
        Dim CLR As String
        With Sheet1
            Set CL = .Range("E4", .Cells(.Rows.Count, "E").End(xlUp))
            Set AA = .Range("J4", .Cells(.Rows.Count, "J").End(xlUp))
            Frm1 = Application.WorksheetFunction.SumIf(CL, ComboBox1, AA)
            frmMain.TextBox1 = Frm1
        End With
    End Sub

+ 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