Need help using VBA to copy data from one sheet into another sheet based on specific date

B1EADDED

New Member
Joined
Nov 28, 2016
Messages
6
Hi all,

I'm very new to VBA and need help copying data from one sheet into another sheet based on a specific date.

I am in charge of invoicing business for the hours employees have worked. This is a large business with a large number of employees and copying and pasting manually takes a lot of time.

I have two sheets. One called 'TIMESHEET' which logs all employees hours that worked. The other called 'DAILY INVOICE' which is in the form of an invoice that shows the client all employees and the hours they worked.

I would like to:
- Enter a specific date in 'DAILY INVOICE' in box I3.
- Excel automatically searches for this date in column B in sheet 'TIMESHEET'
- Excel then copies that data from 'TIMESHEET' for that specific date from columns C, D, E, F, G, H.
- Then paste it into 'DAILY INVOICE' in row 12, column A, (B+C), (D+E+F), G, H, I. (brackets mean the columns are merged). Columns are merged due to invoice information from rows 1 - 10.

The headings for the columns in both sheets are:[TABLE="width: 921"]
<tbody>[TR]
[TD="class: xl69, width: 133"]ID/BADGE NO[/TD]
[TD="class: xl64, width: 147"]NAME[/TD]
[TD="class: xl64, width: 185"]TRADE[/TD]
[TD="class: xl65, width: 185"]START TIME[/TD]
[TD="class: xl65, width: 185"]END TIME[/TD]
[TD="class: xl67, width: 86"]TOTAL HOURS
[/TD]
[/TR]
</tbody>[/TABLE]
These appear in row1, starting at column C, of 'Timesheet', and row12, column A of 'DAILY INVOICE'.

Is this possible?

Any help would be so greatly appreciated!! thank you!!
 
Sorry, forgot to mention that i unmerged the cells in 'DAILY INVOICE', so in the 'Timesheet' Columns C, D, E, F, G, H, need to be copied into the 'DAILY INVOICE' sheet starting at row12, column A, B, C, D, E, F, respectively. Therefore the input date should be in F3 now.

Your code works, and columns C:H should be copied over.
But I found another problem I want to fix, its also copying over blank rows in columns C:H. So is it possible to incorporate a statement that tells it not to copy over rows if Column F in 'Timesheets' is blank.
Thanks
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
So I assume you now mean:
You said this in post #1
Enter a specific date in 'DAILY INVOICE' in box I3.

But now your saying:
Enter a specific date in 'DAILY INVOICE' in box F3.

And really you should say Range("F3") not "box" F3

So see if this works:


Code:
Sub My_New_Script()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
Dim ans As Date
ans = Sheets("DAILY INVOICE").Range("F3").Value
'MsgBox ans
Lastrow = Sheets("TIMESHEET").Cells(Rows.Count, "B").End(xlUp).Row
Lastrowa = 12
    For i = 1 To Lastrow
        If Sheets("TIMESHEET").Cells(i, "B") = ans And Cells(i, "F").Value <> "" Then
            Sheets("TIMESHEET").Range("C" & i & ":H" & i).Copy Destination:=Sheets("DAILY INVOICE").Range("A" & Lastrowa)
            Lastrowa = Lastrowa + 1
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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