Forum

How to calculate ba...
 
Notifications
Clear all

How to calculate based on details chosen from combobox?

6 Posts
3 Users
0 Reactions
103 Views
(@belle)
Posts: 6
Active Member
Topic starter
 

Hi, I have a set of data that need to be summarize. I need to calculate for total cost for each person based on criteria that will be chosen from two comboboxes in certain period (example:21Nov2018-20Dec2018). Anyone know how to do this? Please guide me.

Private Sub CommandButton1_Click()

Dim dbsheet, summarysheet As Worksheet
Dim erow As Long
Set dbsheet = ThisWorkbook.Sheets("DB")
Set summarysheet = ThisWorkbook.Sheets("summary")
lr = dbsheet.Cells(Rows.Count, 1).End(xlUp).Row
stdate = [c8]
enddate = [c9]

Range("J12").Value = Application.WorksheetFunction.DSum(Range("DB", E, ComboBox1, ComboBox3))

End If

summarysheet.Range("E2").Value = ComboBox1
summarysheet.Range("F2").Value = ComboBox3
summarysheet.Range("G2").Value = counter

End Sub

Private Sub UserForm_Initialize()

Dim d As Object, va, i As Long
Set d = CreateObject("scripting.dictionary")

d.CompareMode = vbTextCompare
va = Sheets("DB").Range("F2", Sheets("DB").Cells(Rows.Count, "F").End(xlUp))
For i = 1 To UBound(va, 1)
d(va(i, 1)) = ""
Next
ComboBox1.List = d.keys

d.RemoveAll
va = Sheets("DB").Range("K2", Sheets("DB").Cells(Rows.Count, "K").End(xlUp))
For i = 1 To UBound(va, 1)
d(va(i, 1)) = ""
Next
ComboBox3.List = d.keys

End Sub

 
Posted : 05/01/2019 5:31 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

Can you please supply a workbook with sample data.

Thx

Phil

 
Posted : 07/01/2019 10:16 pm
(@belle)
Posts: 6
Active Member
Topic starter
 

Here the file.

 
Posted : 07/01/2019 11:40 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Fatyn

From your example, you only need 2 values from the combo box i.e. Name and Job Allocation.

The formula for the summary calculation can be placed directly into the worksheet without using the macro.

See if this helps.

Sunny

 
Posted : 08/01/2019 2:53 am
(@belle)
Posts: 6
Active Member
Topic starter
 

Thank you Sunny. it helps a lot

 
Posted : 09/01/2019 3:12 am
(@sunnykow)
Posts: 1417
Noble Member
 

You are welcome

 
Posted : 09/01/2019 11:25 am
Share: