copy rows from table with criteria and paste to end of another table

Pierrepolux

New Member
Joined
Feb 24, 2018
Messages
1
Hello Everyone,

i am trying to copy raws/data from one table with 2 cumulative criteria: Hours & Jobcode should be completed.
I then need to paste it at the end of another table.
I have the following issues with my current code:
- No critera for copying
- Copy all raws until last row with data (even if there is a blank row in-between)
- Past properly at the end of the table but sometimes does not extend the original table. This is when it starts to get messy, as it will then paste on the precedent pasted data while erading them

Here is the code:

Sub AddDay()

Dim answer As Integer
answer = MsgBox("Are you sure you want to validate this daily Timesheet?", vbYesNo + vbQuestion, "Validate Daily Timesheet")
Dim Tbl As ListObject
Set Tbl = ThisWorkbook.Worksheets("Daily Timesheet").ListObjects("Table5")
Dim lRow As Long
Dim lRow2 As Long
lRow2 = Tbl.ListColumns(3).Range.Rows.Count
lRow = Tbl.ListColumns(3).Range(lRow2, 1).End(xlUp).Row

If answer = vbYes Then
If Worksheets("YTD Timesheet").Range("A2") = "" Then
Worksheets("Daily Timesheet").Range("A" & 2 & ":F" & lRow).Copy
With Worksheets("YTD Timesheet").Range("A2")
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteValues
End With
Tbl.DataBodyRange.Columns(3).Resize(, 4).ClearContents
Else
Worksheets("Daily Timesheet").Range("A" & 2 & ":F" & lRow).Copy
With Worksheets("YTD Timesheet").Range("A1").End(xlDown).Offset(1, 0)
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteValues
End With
Tbl.DataBodyRange.Columns(3).Resize(, 4).ClearContents
End If
Else
MsgBox "Please finish completing the Timesheet and validate it", vbExclamation, "Complete Timesheet"
End If


End Sub

Could you please help me?
Thank you very much

John
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Watch MrExcel Video

Forum statistics

Threads
1,099,684
Messages
5,470,116
Members
406,681
Latest member
sachinmasurkar

This Week's Hot Topics

Top