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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top