vba form

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:

[TABLE="class: cms_table, width: 1415"]
<tbody>[TR]
[TD]Table1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Table4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Worker names[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Worker Supervisor[/TD]
[TD]WS hours[/TD]
[TD]Worker1[/TD]
[TD]W1 Hours[/TD]
[TD]Worker2[/TD]
[TD]W2 Hours[/TD]
[TD]Worker3[/TD]
[TD]W3 Hours[/TD]
[TD]Worker4[/TD]
[TD]W4 Hours[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]KEVIN[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]KEVIN[/TD]
[TD]8[/TD]
[TD]NIMA[/TD]
[TD][/TD]
[TD]MATTHEW[/TD]
[TD][/TD]
[TD]GARY[/TD]
[TD][/TD]
[TD]TIMOTHY[/TD]
[TD]4,5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]NIMA[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]NIMA[/TD]
[TD][/TD]
[TD]MATTHEW[/TD]
[TD][/TD]
[TD]GARY[/TD]
[TD]4[/TD]
[TD]TIMOTHY[/TD]
[TD]2[/TD]
[TD]JOSE[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]MATTHEW[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]MATTHEW[/TD]
[TD]7[/TD]
[TD]GARY[/TD]
[TD][/TD]
[TD]TIMOTHY[/TD]
[TD]4[/TD]
[TD]JOSE[/TD]
[TD][/TD]
[TD]LARRY[/TD]
[TD]4,5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]GARY[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
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]
[TD][/TD]
[TD][/TD]
[TD]GREGORY[/TD]
[TD][/TD]
[TD]KEVIN[/TD]
[TD][/TD]
[TD]NIMA[/TD]
[TD]6[/TD]
[TD]MATTHEW[/TD]
[TD]8[/TD]
[TD]GARY[/TD]
[TD]8[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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