Carl Stephens
New Member
- Joined
- Jan 3, 2017
- Messages
- 46
- Office Version
- 365
Hello All,
I have the below code that filters on one tab and copies the desired cells which are then pasted onto another sheet, which works well.....and I am wanting to add, per the code below, a similar command that filters the wsDest tab but I am getting an error on the red ELSE below, stating Else Without If....anyone know the fix for this? Thanking you in advance.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("H4")) Is Nothing Then
Dim wsData As Worksheet
Dim wsDest As Worksheet
Dim lr As Long
Application.ScreenUpdating = False
Set wsData = Worksheets("EPS")
Set wsDest = Worksheets("OT")
wsData.Unprotect ("EPS")
wsDest.Unprotect ("OT")
lr = wsData.Cells(Rows.Count, "AP").End(xlUp).Row
If wsData.FilterMode Then wsData.ShowAllData
With wsData.Rows(1)
.AutoFilter Field:=53, Criteria1:="No"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("BD3:BJ" & lr).SpecialCells(xlCellTypeVisible).Copy
wsDest.Range("D" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 2 & " new employee records were found and copied to copied to this tab." & vbCrLf & _
"Next, update any crew that are showing as Scheduled in column C and send joining instructions if required.", vbInformation
Else
MsgBox "No new employee records found. Please check to see who has been 'Scheduled' per column C and add the new posting details, and who need joining instructions if required.", vbInformation
End If
.AutoFilter Field:=53
wsDest.EnableAutoFilter = True
wsData.EnableAutoFilter = True
wsData.Protect Password:="EPS", UserInterfaceOnly:=True
wsDest.Protect Password:="OT", UserInterfaceOnly:=True
Application.Goto (ActiveWorkbook.Sheets("OT").Range("A1"))
lr = wsData.Cells(Rows.Count, "AP").End(xlUp).Row
If wsData.FilterMode Then wsData.ShowAllData
With wsData.Rows(1)
.AutoFilter Field:=52, Criteria1:="Yes"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("BK3:BL" & lr).SpecialCells(xlCellTypeVisible).Copy
With wsDest.Rows(10)
.AutoFilter Field:=2, Criteria1:="Scheduled"
wsDest.Range("O" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 2 & " new employee records were found and copied to copied to this tab." & vbCrLf & _
"Next, update any crew that are showing as Scheduled in column C and send joining instructions if required.", vbInformation
Else
MsgBox "No new employee records found. Please check to see who has been 'Scheduled' per column C and add the new posting details, and who need joining instructions if required.", vbInformation
End If
.AutoFilter Field:=52
wsDest.EnableAutoFilter = True
wsData.EnableAutoFilter = True
wsData.Protect Password:="EPS", UserInterfaceOnly:=True
wsDest.Protect Password:="OT", UserInterfaceOnly:=True
Application.Goto (ActiveWorkbook.Sheets("OT").Range("A1"))
End With
End If
End If
End Sub
I have the below code that filters on one tab and copies the desired cells which are then pasted onto another sheet, which works well.....and I am wanting to add, per the code below, a similar command that filters the wsDest tab but I am getting an error on the red ELSE below, stating Else Without If....anyone know the fix for this? Thanking you in advance.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("H4")) Is Nothing Then
Dim wsData As Worksheet
Dim wsDest As Worksheet
Dim lr As Long
Application.ScreenUpdating = False
Set wsData = Worksheets("EPS")
Set wsDest = Worksheets("OT")
wsData.Unprotect ("EPS")
wsDest.Unprotect ("OT")
lr = wsData.Cells(Rows.Count, "AP").End(xlUp).Row
If wsData.FilterMode Then wsData.ShowAllData
With wsData.Rows(1)
.AutoFilter Field:=53, Criteria1:="No"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("BD3:BJ" & lr).SpecialCells(xlCellTypeVisible).Copy
wsDest.Range("D" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 2 & " new employee records were found and copied to copied to this tab." & vbCrLf & _
"Next, update any crew that are showing as Scheduled in column C and send joining instructions if required.", vbInformation
Else
MsgBox "No new employee records found. Please check to see who has been 'Scheduled' per column C and add the new posting details, and who need joining instructions if required.", vbInformation
End If
.AutoFilter Field:=53
wsDest.EnableAutoFilter = True
wsData.EnableAutoFilter = True
wsData.Protect Password:="EPS", UserInterfaceOnly:=True
wsDest.Protect Password:="OT", UserInterfaceOnly:=True
Application.Goto (ActiveWorkbook.Sheets("OT").Range("A1"))
lr = wsData.Cells(Rows.Count, "AP").End(xlUp).Row
If wsData.FilterMode Then wsData.ShowAllData
With wsData.Rows(1)
.AutoFilter Field:=52, Criteria1:="Yes"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("BK3:BL" & lr).SpecialCells(xlCellTypeVisible).Copy
With wsDest.Rows(10)
.AutoFilter Field:=2, Criteria1:="Scheduled"
wsDest.Range("O" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 2 & " new employee records were found and copied to copied to this tab." & vbCrLf & _
"Next, update any crew that are showing as Scheduled in column C and send joining instructions if required.", vbInformation
Else
MsgBox "No new employee records found. Please check to see who has been 'Scheduled' per column C and add the new posting details, and who need joining instructions if required.", vbInformation
End If
.AutoFilter Field:=52
wsDest.EnableAutoFilter = True
wsData.EnableAutoFilter = True
wsData.Protect Password:="EPS", UserInterfaceOnly:=True
wsDest.Protect Password:="OT", UserInterfaceOnly:=True
Application.Goto (ActiveWorkbook.Sheets("OT").Range("A1"))
End With
End If
End If
End Sub