Solved

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

Posted on 2015-02-09
7
54 Views
Last Modified: 2015-02-10
From the time sheet form button, can the units per hour be calculated
StlFunction-Analisys-2015-v1f.xlsm
0
Comment
Question by:bjfulkerson
  • 3
  • 3
7 Comments
 
LVL 24

Expert Comment

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

Accepted Solution

by:
broro183 earned 500 total points
ID: 40600459
hi,

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


hth
Rob
0
 

Author Comment

by:bjfulkerson
ID: 40600466
Rob,
When you say behind, what does that mean?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 

Author Closing Comment

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

Expert Comment

by:broro183
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.

Rob
0
 

Author Comment

by:bjfulkerson
ID: 40600473
Got it . Thanks
0
 
LVL 10

Expert Comment

by:broro183
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.

Rob
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

809 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