Populate a user form with a formula to calculate units per hr

Posted on 2015-02-09
Last Modified: 2015-02-10
From the time sheet form button, can the units per hour be calculated
Question by:bjfulkerson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 24

Expert Comment

by:Phillip Burton
ID: 40600246
Don't understand the question.
LVL 10

Accepted Solution

broro183 earned 500 total points
ID: 40600459

Try adding the following code into the code behind the TimeSheetEntry Form module. This seems to hold up okay under some light testing.

Private Sub TxtTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call CalcAndUpdateUPH_tbx
End Sub

Private Sub TxtUnits_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call CalcAndUpdateUPH_tbx
End Sub

Sub CalcAndUpdateUPH_tbx()
With Me
        'test that both fields are populated.
        If Len(.TxtTime.Value) * Len(.TxtUnits.Value) Then
            'validate that the entries are numeric.
            If IsNumeric(.TxtTime.Value) And IsNumeric(.TxtUnits.Value) Then
                .TxtUPH.Value = .TxtUnits.Value / .TxtTime.Value
            End If
        End If
    End With
End Sub

Open in new window


Author Comment

ID: 40600466
When you say behind, what does that mean?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Closing Comment

ID: 40600471
I added it to the top of the TimesheetEntry and it worked great!  Thanks for adding the explanations too!
LVL 10

Expert Comment

ID: 40600472
Sorry, I didn't word that very well.

It may just be my settings but when I double (left) click on the TimeSheetEntry item in the Forms folder within the Project Pane of the VBE, the result is that the Userform appears (on the right for me). To see the code relating to the Userform, I press [F7] or right click on on the item in the lefthand pane & choose "view code". This then shows the code relating to the userform eg "Private Sub UserForm_Initialize()" or "Private Sub Calendar1_Click()".

I consider this code as being "behind" the userform.


Author Comment

ID: 40600473
Got it . Thanks
LVL 10

Expert Comment

ID: 40600480
Awesome, I'm pleased I could help :-)

Now that it is a calculated field, I suggest changing the appearance of the textbox so that users can easily recognise that they don't need to populate it (eg "grey it out" by changing the backcolour to something like &H80000000&.
Or, if you want to get more complicated, you could allow users to enter values into any two of the three fields & then have the code calculate whichever one is the remaining empty field.


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel shared spreadsheet 12 38
Excel to show a dynamic Picklist at level2 2 22
copy down array 24 31
Zip Codes Excel Spreadsheet 4 21
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question