dcsimg
Results 1 to 4 of 4

Thread: VBA: summary based on input from combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    2

    VBA: summary based on input from combobox

    Hi,
    I'm working on a database and I need to do a summary based on input selected from two comboboxes. After the input selected, the data will calculate for total cost on certain period of time(example:21 Oct 2018 - 20 Nov 2018) and display in new sheet. This what i have now. Can somebody help me on how to change the code so that the calculation will be based on data selected from the comboboxes?

    Code:
    Private Sub CommandButton1_Click()
    
    Dim dbsheet As Worksheet
    Set dbsheet = ThisWorkbook.Sheets("DB")
    lr = dbsheet.Cells(Rows.Count, 1).End(xlUp).Row
    selrow = Selection.Row
    
    'assignment
    asg = dbsheet.Cells(selrow, 6)
    'labor allocation
    labor = dbsheet.Cells(selrow, 11)
    
    'loop
    For x = 2 To lr
    If dbsheet.Cells(x, 6) = asg And dbsheet.Cells(x, 11) = labor Then
    counter = counter + dbsheet.Cells(x, 5)
    
    End If
    Next x
    MsgBox "Total qty " & asg & " for " & labor & " is " & counter
    
    End Sub

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,752

    Re: VBA: summary based on input from combobox

    Thread moved to Office Development, since the language is VBA.
    My usual boring signature: Nothing

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,882

    Re: VBA: summary based on input from combobox

    do the comboboxes contain the dates?

    can you post a workbook with some sample data (zip first) for us to see?
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    2

    Re: VBA: summary based on input from combobox

    The comboboxes do not include the dates. Combobox1 is name, combobox2 is job allocation. I need to calculate cost based on these info for a month. But the dates will be changed for every month. Any idea how to do it?

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width