Formula help

G

Guest

Hello, I have a form in my excel workbook that is brought up by a buttons on
click event. On this form I have 5 text boxes.
1) txtMinutesWorked
2) txtRunMinutes
3) txtDelayMinutes
4) txtDelayHours
5) txtDelayInDecimal

Here is an example calculation of what im looking for the form to calculate.
If I enter 480 into “txtMinutesWorked†and I enter 240 into “txtRunMinutesâ€
then “txtDelayMinutes†would calculate a number 240 and “txtDelayHours†would
calculate a number 4h 0m and “txtDelayInDecimal†would calculate 4.0. What
VBA would I put in what boxes to get the numbers I need calculated? I have
this working on a worksheet but I wanted to do it in a popup in VB..

Thanks!
 
G

Guest

This will get you going.

Now, just so you know, this doesn't recalculate for minutes more then 60,
and convert it to hours, then remaining minutes.

Just play with the numbers in your two input textboxes and you will see what
i mean.

--------------------------------------------
Private Sub txtRunMinutes_Change()
Dim sHours As String
sHours = (Me.txtMinutesWorked.Text - Me.txtRunMinutes.Text) / 60

Dim sHours2 As String
sHours2 = FormatNumber(Me.txtMinutesWorked.Text, 0)

Dim sMinutes As String
sMinutes = Me.txtMinutesWorked.Text

Dim sMinutes2 As String
sMinutes2 = FormatNumber(Me.txtRunMinutes.Text, 0)

Dim sTotalMinutes As String
sTotalMinutes = sHours2 - sMinutes2
Me.txtDelayMinutes.Text = sTotalMinutes

Dim sTotalHours As String
sTotalHours = FormatNumber(sHours, 0) & "h "

Dim sTotalMinutes2 As String
sTotalMinutes2 = sTotalMinutes -
FormatNumber(Me.txtRunMinutes.Text, 0)

Dim sLessMinutes As String
sLessMinutes = sTotalHours & sTotalMinutes2 & "m"
Me.txtDelayHours.Text = sLessMinutes

Me.txtDelayInDecimal.Text = FormatNumber(sHours, 1)
End Sub

------------------------------------------------

There is always a better, more streamlined way of doing it, but i just blew
it out to give you a quick answer.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top