Ok, let's go in reverse order. To your last question, "Is my end goal possible?", the answer is "sure." I don't quite follow your reasoning, but if you prefer to use Excel, so be it. I do think, though, that this going to be a painful way of recording PTO. What if, for example, I take a week off? Do I have to fill out this form once for each day?
To continue moving in reverse, your buttons need to do something. It's unclear from what you've posted if cmdCancel
and cmdOK
are subs that you've defined elsewhere so let's pretend they aren't. In your Cancel button you need to do one basic thing, close the form. That should be as simple as this, Unload Me
.
Your OK button is the crucial piece of your macro. It's where you stitch together the values the user has entered. It's also where you do something with your option buttons. You don't actually assign values to the option buttons, you check their Value properties. So, when you users click OK the code that runs will have something in it like this:
If OptionButton1.Value = True Then
'Put 1 in the cell.
Else
'Put .5 in the cell.
End if
Note that there's no need to explicitly check OptionButton2, since you only have two choices.
Finally, the dates. It sounds like the dates are already in your spreadsheet, in some particular row. What you need to do here is loop through the cells in that row and pull the values into the list of the combo box. This should get you started. Put it the UserForm_Activate
form event:
Dim i As Long
i = 1
Do While ThisWorkbook.ActiveSheet.Cells(DateRow, i).Value <> ""
Me.ComboBox1.AddItem (ThisWorkbook.ActiveSheet.Cells(DateRow, i).Value)
i = i + 1
Loop
Now we return to the OK button. You need to get the selection that was made in the date combo box. To do that you need to read the ListIndex
property of the combo box and add one to it. (Adding 1 accounts for the fact that the list in the combo box starts 0, not 1.) The number that is the returned will be the column in which you insert your data.
The complete code for the OK button would be something like:
Dim Col As Long
Dim Row As Long
Dim PTOValue As Long
Col = DateComboBox.ListIndex + 1
Row = EmployeeNameComboBox.ListIndex + 1
If FullDayComboBox.Value = True Then
PTOValue = 1
Else
PTOValue = .5
End if
ThisWorkbook.ActiveSheet.Cells(DateRow, i).Value = PTOValue
Hopefully this will get you started.