Hello again. I am in over my head again and could use some help after a lot of searching.
On the Active Sheet (Employee Pay Slip), cell (D2) has a date in it . I'm trying to extract the Month from the date and assign it to a variable as the name of a worksheet where I need to extract a list of employees from. In essence, I'm trying to get those employees names into cells of each pay slip E10, O10, E27, O27 through E214 & O214 (17 rows apart). Two Slips are shown side by side and I have 26 slips total. After the name extraction is placed in Column V1, the Module counts the amount of names and puts that count into H3 (EntireRow.Hidden = True/False). This part works fine. The problem is getting the month name from a date to use as a variable.
Since it wasn't working for me I tried extracting the month with a formula then referring to that cell H2
I'm learning so any help would be great. Also, if you see anything that can be modified to streamline the process I'm totally open to all mods.
Thanks in advance guys.
On the Active Sheet (Employee Pay Slip), cell (D2) has a date in it . I'm trying to extract the Month from the date and assign it to a variable as the name of a worksheet where I need to extract a list of employees from. In essence, I'm trying to get those employees names into cells of each pay slip E10, O10, E27, O27 through E214 & O214 (17 rows apart). Two Slips are shown side by side and I have 26 slips total. After the name extraction is placed in Column V1, the Module counts the amount of names and puts that count into H3 (EntireRow.Hidden = True/False). This part works fine. The problem is getting the month name from a date to use as a variable.
Since it wasn't working for me I tried extracting the month with a formula then referring to that cell H2
I'm learning so any help would be great. Also, if you see anything that can be modified to streamline the process I'm totally open to all mods.
Thanks in advance guys.
VBA Code:
Sub ClrCpyPyRl()
Dim MthCell As String
Dim wsMth As Worksheet
Dim wsEmpPySlp As Worksheet
Dim mthLR As Long
Dim mthHdrRow As Long
Dim Count As Long
'On Error Resume Next '(Off to find error)
Application.EnableEvents = False
Application.ScreenUpdating = False
'------------------------------------------------------------------------------------
'Get Name of month from date cell (D2) to use as Worksheet name
MthCell = Range("H2").Value 'Cell H2 has a formula =TEXT($D$2,"mmmm") extracting the month from D2
'MthCell = MonthName(Range("D2")) 'Invalid Procedure Call or Argument
Set wsMth = Worksheets(MthCell)
'------------------------------------------------------------------------------------
Set wsEmpPySlp = Sheets("Employee Pay Slip")
mthHdrRow = 8 'Header Row No. on Month sheet
With wsMth
.Unprotect Password:=""
mthLR = .Range("C" & Rows.Count).End(xlUp).Row
' Check for no data on Month sheet
If mthLR > mthHdrRow Then
'------------------------------------------------------------------------------------
'Sheet (wsMth) where data is copied from
Sheets(wsMth).Range("C8:C" & mthLR).AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets(wsEmpPySlp).Range("C2:D2"), CopyToRange:=Range("'Employee Pay Slip'!Extract"), _
Unique:=False
'------------------------------------------------------------------------------------
Count = Range("V2").End(xlDown).End(xlDown).End(xlUp).Rows.Count
Range("H3").Value = Count
End If
End With
Sheets(MthCell).Protect Password:=""
Sheets("Payroll").Protect Password:=""
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub