Hi all,
Apologies if this type of thing has been asked before but I've created the following macro in a timesheet I've created for my work:
Sub CompletedTime()
Sheets("Timesheet").Select
Range("A4:M53").Select
Selection.Copy
Sheets("Completed Time").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells.Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Completed Time").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Completed Time").Sort.SortFields.Add2 Key:=Range( _
"B2:B1048576"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Completed Time").Sort
.SetRange Range("A1:M1048576")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2").Select
End Sub
As you can tell, this is my attempt at cleaning up (albeit slightly) a recorded macro that, originally, was meant to copy all data from a range of cells (that have formulas in them) from one worksheet and paste those values to another worksheet and then sort it. It's meant to keep a record of all the time I submit to our timekeeping software and it works fine. The only issue, other than having messy code, is that it will always copy from the entire range whether there is a value there or not. Would someone be able to suggest a way of only copying columns A to M of rows when the formula in column A is equal to a value, not just a formula?
Bookmarks