Sub transferTT2S()
Dim wss As Worksheet, wst As Worksheet, r As Range, r2 As Range
Dim iRows As Long, StartRow As Long
Set wss = Sheets("Summary")
Set wst = Sheets("TaskTracker")
' Count the rows to be copied (and inserted)
Set r2 = wst.[A:A].Find("Total Hours").Offset(-1)
Set r2 = Range(r2, wst.[A7])
Set r2 = Union(r2, r2.Offset(, 3))
iRows = r2.Rows.Count
' find the next empty row
Set r = wss.Range("A" & Range("A1").CurrentRegion.Rows.Count)
StartRow = r.Row
' Now insert the number of rows. Select the rows first
' as after inserting we need to ungroup them from the previous grouping
r.EntireRow.Resize.EntireRow.Resize(rowsize:=iRows).Select
Selection.Insert
Selection.Rows.Ungroup
'now copy the data into the inserted rows and format
Set r = r.Offset(-iRows)
r.Value = wst.[B3].Value
r2.Copy
r.Offset(, 1).PasteSpecial xlPasteValues
r.Offset(, 2).Resize(r2.Rows.Count, 2).NumberFormat = "[h]:mm:ss"
r.Offset(, 2).Resize(r2.Rows.Count, 2).HorizontalAlignment = xlCenter
r.Offset(, 3).Value = r2.Rows(r2.Rows.Count).Cells(1).Offset(1, 1).Value
With r.Rows(1).Columns(1).Resize(, 4).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
' Lastly group the new data
Rows(StartRow + 1 & ":" & StartRow + iRows - 1).Select
Selection.Rows.Group
End Sub
|