aboly8000

Board Regular
Joined
Sep 4, 2019
Messages
59
Hello
I need a vba form with two fields, one of which is a drop down list of names and the other is a decimal value to store names in the cell and a decimal in the comment.
Then I want to formulate and calculate on the decimals inside the comments.
Can anyone help me?
 
I have arranged the two tables as follows. This allows you in Table1 to sort on position or name, etc. It also allows you to do an easy pivottable.



The pivot table could look something like:



Then I have modified the userform slightly. I have added a textbox called tbxPosition, to hold the position of the selected person:



In use the form will look like:



And the code to run the userform:
Code:
Option Explicit


Private Sub btnCancel_Click()
    Unload Me
End Sub




Private Sub btnOK_Click()
    'find name in table1 and add hours in column behind
    Dim rFound As Range
    Dim vSp As Variant
    
    vSp = Split(tbxHours, ":")
    Set rFound = ActiveSheet.ListObjects("Table1").DataBodyRange.Find(what:=cbxNames)
    rFound.Offset(0, 2) = rFound.Offset(0, 2) + vSp(0) + vSp(1) / 60




End Sub


Private Sub cbxNames_Change()
    Dim rFound As Range
    If Len(cbxNames) Then
    
        Set rFound = ActiveSheet.ListObjects("Table1").DataBodyRange.Find(what:=cbxNames)
        If Not rFound Is Nothing Then
            tbxPosition = rFound.Offset(0, 1)
        Else
            tbxPosition = ""
        End If
    End If
End Sub


Private Sub tbxHours_Change()
    If Len(tbxHours) = 2 And InStr(1, tbxHours, ":") = 0 Then
        tbxHours = tbxHours & ":"
    End If
End Sub






Private Sub tbxHours_Enter()
    tbxHours = ""
End Sub




Private Sub tbxHours_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        If Len(tbxHours.Value) = 0 Then
            tbxHours.Value = "00:00"
        ElseIf Len(tbxHours.Value) = 4 Then
            tbxHours.Value = "0" & tbxHours.Value
        End If
        If IsDate(tbxHours.Value) And Len(tbxHours.Text) = 5 Then
        Else
            MsgBox "Input Hour like this Example 05:35"
            tbxHours.Text = "00:00"
        End If
End Sub




Private Sub UserForm_Initialize()
    With cbxNames
        .RowSource = ActiveSheet.ListObjects("Table4").ListColumns(1).DataBodyRange.Address
    End With
    tbxHours = "00:00"
End Sub
My info table has other columns too, so I can't change it. The table must be as follows:

Table1Table4
Worker namesWorker SupervisorWS hoursWorker1W1 HoursWorker2W2 HoursWorker3W3 HoursWorker4W4 Hours
KEVINKEVIN8NIMAMATTHEWGARYTIMOTHY4,5
NIMANIMAMATTHEWGARY4TIMOTHY2JOSE2
MATTHEWMATTHEW7GARYTIMOTHY4JOSELARRY4,5
GARYGARYTIMOTHY2JOSELARRY5JEFFREY5
TIMOTHYTIMOTHYJOSELARRYJEFFREY6FRANK4,333333333
JOSEJOSELARRY5JEFFREYFRANKSCOTT0
LARRYLARRY5JEFFREY6FRANK3SCOTT7ERIC7
JEFFREYJEFFREYFRANKSCOTTERIC7STEPHEN7
FRANKFRANKSCOTT7ERIC3STEPHENANDREW0
SCOTTSCOTTERIC7STEPHEN3ANDREWRAYMOND0
ERICERICSTEPHENANDREW6RAYMOND4GREGORY4
STEPHENSTEPHENANDREWRAYMONDGREGORY5KEVIN5
ANDREWANDREWRAYMONDGREGORY6KEVIN6NIMA6
RAYMONDRAYMONDGREGORY7KEVINNIMA7MATTHEW7
GREGORYGREGORYKEVINNIMA6MATTHEW8GARY8

<tbody>
</tbody>
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
In that case you need to use the first version of the code.

And to do the pivot for such a table depends on what you want to get out. I can only think of a work-around: if your workerstable doesn't change too much then you can add another table laid out in the way of my second version of table4. Then link them with formula. That second table can easily be pivotted
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,655
Members
448,975
Latest member
sweeberry

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