I have a workbook for scheduling purposes. On sheet1 ("Staff") I compile availability. I'd like the macro to sort the data according to column H (availability), select and copy the block of data at the top (anything that has a value in column H), then transfer this info to another sheet ("Schedule"), and delete the transferred rows on sheet1. Everything is working except the copy portion of the code - it sorts properly, selects the proper information, then gets stuck on moving it to another sheet. I keep getting an error on line 28 [Sheets("Schedule").Range("A" & LastRow2).Select]. Below is the code I have in Module 1:
Code:
Sub Archive()
Dim LastRow As Long
Dim LastRow2 As Long
Dim objRows As Range
Dim sendObjTo As Range
Application.ScreenUpdating = False
Worksheets("Staff").Sort.SortFields.Clear
Worksheets("Staff").Sort.SortFields.Add Key:=Range("H1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Staff").Sort
.SetRange Range("A1:I1500")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
LastRow = Range("H:H").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set objRows = Sheets("Staff").Range("A2:I" & LastRow)
objRows.Select
Selection.Copy
LastRow2 = Sheets("Schedule").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets("Schedule").Range("A" & LastRow2).Select
objRows.PasteSpecial (xlPasteAll)
objRows.Delete
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: