Translate Formula into vba code plus more

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
I have developed an employee attendance form that has a dropdown list where the user selects the employee they want to see. The users are interested in seeing the last 24 payroll periods, most recent first. When they complete this, based on the 24 payroll periods, the attendance violations show up in appropriate 1-31 columns. I am in the process of setting up a UserForm instead of using formulas in a spreadsheet.
Is there a way to duplicate this excel formula: =MAX(IF(Table1[Employee]=EmployeeName,Table1[SDay]))
I have started writing the code but need help with:

1. CBO_EMPLOYEE_CHANGE event - keep getting an error 13 type mismatch on my code and need some help.
2. How to I populate the 24 date textboxes - Order: Newest to Oldest

Here is snippet of my Table1 where the data is stored:
1592862383938.png


Here is a snippet of my UserForm layout:
1592862439887.png


Code I have so far:
VBA Code:
Private Sub UserForm_Initialize()
    Dim i As Long
Dim va, x
    Dim d As Object
    Set d = CreateObject("scripting.dictionary")
va = Sheets("Absentee").Range("C3:C100000")
For Each x In va
d(x) = Empty
Next
CBO_EMPLOYEE.List = d.keys
End Sub

Private Sub CBO_EMPLOYEE_CHANGE()
If Me.CBO_EMPLOYEE.ListIndex > -1 Then
Me.TXT_DATE1.value = WorksheetFunction.VLookup(CLng(Me.CBO_EMPLOYEE.value), _
Sheets("Absentee").Range("Table1"), 11, False)
End If
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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