Subtract Values In Combo Box

NeedsHelp2

New Member
Joined
Nov 20, 2005
Messages
22
On a Useform I've a two combo boxes which are filled with the times in 1 min intervals over a period of 24 hours.

Also on the user form I've a label which I want to populate with the variation between the two times once both combo boxes have data selected.

I also need to show the output in the label as a time format hh:mm


Any suggestions would be appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I use this piece of code to populate the combo boxes

Dim NoDupesE As New Collection
Dim ListSortE As Range
Sheets("LookUps").Select
Range(("J2"), Range("J65536").End(xlUp)).SpecialCells(xlCellTypeVisible).Activate
Selection.Activate

On Error Resume Next

For Each cell In Selection
NoDupesE.Add cell.Value, CStr(cell.Value)

Next cell

On Error GoTo 0
'Dim lngIndex As Long
For lngIndex = 1 To NoDupesE.Count
cmbE.AddItem Format$(NoDupesE(lngIndex), "hh:mm")
Next lngIndex
 
Upvote 0
I do the same thing with 2 combo boxes. Only I have all the times in cells (f3:f1442) then I use the "cell link" of the combo boxes to subtract the difference.

I can go into more detail if you think it will help.

Michael
 
Upvote 0
In cells:
=Sheet1!$F$3:$F$1442
I have all my times listed.

I have a combo box that has a cell link to C5

I have a 2nd combo box which links to C7

I have this in B10:
=IF(C7>C5,(C7-C5)+1,(C7+1440)-C5+1)
This is in case they work from 11pm to 3am.

In cell B12:
=ROUNDDOWN(B10/60,0)
In cell B13
=ABS(((B12*60)-B10)+1)

Then in cell B2 I have:
="He Worked "&B12&" Hours "&B13&" Minutes"

Hope some of this helps you. I know I really go the round about way to do things, but it gets the results I need.

Hope this Helps!
Michael
 
Upvote 0
Thanks, but need to set the result to show in the label as soon as both combo boxes have been selected.

Can anyone assist further?
 
Upvote 0
Sorry, I missed a part.

Select the text box and goto the formula bar
and enter the cell reference as =A1 or wherever you have the data.
="He Worked "&B12&" Hours "&B13&" Minutes"

This should work!

Michael
 
Upvote 0
I'm almost there I think. The code below works but I'm having a problem with getting the result to appear as hh:mm. Can someone please advise how I can format it correctly?

Label33 = TimeValue(cmbF.Value) - TimeValue(cmbE.Value)
 
Upvote 0

Forum statistics

Threads
1,203,460
Messages
6,055,556
Members
444,797
Latest member
18ecooley

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top