• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Changing hours into decimal for calculating

Hello,
I have 3 textboxes in an excel userform
in the first i fill in the hours
in the second comes the price
in the thirt i should have the result
example
in textbox 1 i put 1.45 (hours: 1 hour and 45 minutes)
in textbox 2 i put 42 (price)
the result in textbox 3 shoul be 73,5
Thanks in advance
 
=(INT(Textbox1.value)+(Textbox1.value - INT(Textbox1.value)) * 100/60) * Textbox2.value
 
Hello,
Thank you for your quick response, but i still have a few prolems
I get value 5250 instead of 52,50 and when i use for example 0.45 (45 minutes) everything less than 1 hour, the caluclation is not correct
I use this code now
Code:
Private Sub TextBox12_Change()
TextBox13.Value = (Int(TextBox12.Value) + (TextBox12.Value - Int(TextBox12.Value)) * 100 / 60) * TextBox11.Value
End Sub
can you help me a bit further pls
 
The Math is correct
I think the issue is that you are using the code in a Textbox Change event
This will execute everytime you type anything in Textbox12

You are better to use a CommandButton

eg:
Code:
Private Sub CommandButton1_Click()
TextBox13.Value = (Int(TextBox12.Value) + (TextBox12.Value - Int(TextBox12.Value)) * 100 / 60) * TextBox11.Value
End Sub

You may also want to consider using the Textbox Enter event
Code:
Private Sub CommandButton1_Enter()
TextBox13.Value = (Int(TextBox12.Value) + (TextBox12.Value - Int(TextBox12.Value)) * 100 / 60) * TextBox11.Value
End Sub

also check that you have used Textbox12 and 11 in the correct locations as the first example used Textbox1 to hold the hours and now you are using Textbox12
 
Back
Top