michaeltsmith93
Board Regular
- Joined
- Sep 29, 2016
- Messages
- 83
Hi,
I have an AutoFilter on Worksheet("Tracker"), and I'd like to disable it while this sub runs as part of a UserForm. At the moment, it autofilters the copied range and then finds the last empty row again and inputs the information from the UserForm. What I'd like it to do is input that info into the row that I've copied to the last empty row, and then reenable the auto-filter so it ends up in the right place. The autofilter code is in the second code box below, and that's housed in the sheet's code.
I have an AutoFilter on Worksheet("Tracker"), and I'd like to disable it while this sub runs as part of a UserForm. At the moment, it autofilters the copied range and then finds the last empty row again and inputs the information from the UserForm. What I'd like it to do is input that info into the row that I've copied to the last empty row, and then reenable the auto-filter so it ends up in the right place. The autofilter code is in the second code box below, and that's housed in the sheet's code.
Code:
Private Sub OK_Click()
Dim ERow As Long
Dim ws As Worksheet
Set ws = Worksheets("Tracker")
'find first empty row
ERow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for input
If Trim(Me.ptmember.Value) = "" Or Trim(Me.StudyRole.Value) = "" Or Trim(Me.MatrixRole.Value) = "" Or Trim(Me.Department.Value) = "" Then
MsgBox "Please fill all fields."
Exit Sub
End If
'copy A6:AP6 to ERow
Range("A6:AP6").Copy Range("A" & ERow)
'place inputs into correct columns in ERow
With ws
.Cells(ERow, 1).Value = Me.ptmember.Value
.Cells(ERow, 2).Value = Me.StudyRole.Value
.Cells(ERow, 4).Value = Me.MatrixRole.Value
.Cells(ERow, 5).Value = Me.Department.Value
End With
'clear contents of input boxes
Me.ptmember.Value = ""
Me.StudyRole.Value = ""
Me.MatrixRole.Value = ""
Me.Department.Value = ""
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Sheets("Tracker").AutoFilter.ApplyFilter
Application.ScreenUpdating = False
End Sub