anna82marie
New Member
- Joined
- Jan 22, 2014
- Messages
- 15
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi everyone,
I need help again. I've written a fleet management spreadsheet and I'm having problems with a piece of code that takes filtered information from one sheet and moves it to another.
Code is as below; A3 is header row, if A4 is empty, code bugs out, where it should just be returning "Nothing to Archive"
Where on earth am I going wrong? Management seem to think I know what I'm doing...... I don't.
I need help again. I've written a fleet management spreadsheet and I'm having problems with a piece of code that takes filtered information from one sheet and moves it to another.
Code is as below; A3 is header row, if A4 is empty, code bugs out, where it should just be returning "Nothing to Archive"
Where on earth am I going wrong? Management seem to think I know what I'm doing...... I don't.
VBA Code:
Sub Move_From_DC_To_Scrapped()
'copy and paste certain columns based on variable in column W
Dim ws1 As Worksheet, ws2 As Worksheet, Lrow As Long, rng As Range
Set ws1 = ThisWorkbook.Sheets("Disposal Criteria")
Set ws2 = ThisWorkbook.Sheets("Archive (Scrapped)")
Call UnprotectDC
Call UnprotectArchive
'TurnOff screen updating
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Lrow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
With ws1
.Range("A3").AutoFilter Field:=23, Criteria1:="Y"
If Range("A3:A" & Lrow).SpecialCells(xlCellTypeVisible).Count > 1 Then
ws1.Range("A4:D" & Lrow).SpecialCells(xlCellTypeVisible).Copy
ws2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
ws1.Range("F4:H" & Lrow).SpecialCells(xlCellTypeVisible).Copy
ws2.Cells(Rows.Count, 1).End(xlUp).Offset(0, 4).PasteSpecial xlPasteValues
ws1.Range("M4:M" & Lrow).SpecialCells(xlCellTypeVisible).Copy
ws2.Cells(Rows.Count, 1).End(xlUp).Offset(0, 7).PasteSpecial xlPasteValues
ws1.Range("U4:U" & Lrow).SpecialCells(xlCellTypeVisible).Copy
ws2.Cells(Rows.Count, 1).End(xlUp).Offset(0, 8).PasteSpecial xlPasteValues
Call DeleteRows_DC
Else
ws1.Range("A3").AutoFilter 'clear the filter
MsgBox "Nothing to Archive"
'TurnOn screen updating
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
End With
Call ProtectDC
Call ProtectArchive
End Sub