amazon_devil
New Member
- Joined
- Jul 30, 2018
- Messages
- 4
I am trying to develop a code that will autofilter a field, that will change month to month.
I have a userform where the user selects the reporting month, then the script finds that month across the top of a structured table, and then drops down 1 row to select the header of the structured table. upon clicking "OK" on the user form.
As the field number "column" will change each time I need to enter this as a variable. I have tried a number of different solutions from other peoples posts, but still no luck.
Private Sub cbOK_Click()
Sheets("Weekly Timesheet").Select
Sheets("Weekly Timesheet").Range("H5").Select
ActiveCell.value = cboRMonth.value
Unload Me
ReportMonth = cboRMonth.value
MsgBox ReportMonth
Sheets("Tracking (DAYS)").Select
Sheets("Tracking (DAYS)").Range("N2").Select
Do Until ActiveCell = ReportMonth
ActiveCell.Offset(0, 1).Select
Loop
ActiveCell.Offset(1, 0).Select
'Tells me what the name of the header is (just to make sure I've got the right one selected).
Dim Col As String
Col = ActiveCell
MsgBox Col
Dim lCol As Long
lCol = ActiveCell.Column
ActiveSheet.ListObjects("Tracking_DAYS").Range(lCol).AutoFilter _
Criterial:=">0", _
Operator:=x1FilterValues
End Sub
I have a userform where the user selects the reporting month, then the script finds that month across the top of a structured table, and then drops down 1 row to select the header of the structured table. upon clicking "OK" on the user form.
As the field number "column" will change each time I need to enter this as a variable. I have tried a number of different solutions from other peoples posts, but still no luck.
Private Sub cbOK_Click()
Sheets("Weekly Timesheet").Select
Sheets("Weekly Timesheet").Range("H5").Select
ActiveCell.value = cboRMonth.value
Unload Me
ReportMonth = cboRMonth.value
MsgBox ReportMonth
Sheets("Tracking (DAYS)").Select
Sheets("Tracking (DAYS)").Range("N2").Select
Do Until ActiveCell = ReportMonth
ActiveCell.Offset(0, 1).Select
Loop
ActiveCell.Offset(1, 0).Select
'Tells me what the name of the header is (just to make sure I've got the right one selected).
Dim Col As String
Col = ActiveCell
MsgBox Col
Dim lCol As Long
lCol = ActiveCell.Column
ActiveSheet.ListObjects("Tracking_DAYS").Range(lCol).AutoFilter _
Criterial:=">0", _
Operator:=x1FilterValues
End Sub