VBA Macro on copy pasting from one workbook to another with loop and conditions

hencra

New Member
Joined
Jan 25, 2017
Messages
2
[TABLE="width: 320"]
<colgroup><col span="5"></colgroup><tbody>[TR]
[TD]Hi, [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]Can you help me with my problem, I want to automate the creation of a DTR given the schedule they have. I have the file where the schedule is in together with all other information called "DTR Creator" and a "DTR Sample" where the cells will be copied. I need to create N numbers of DTR equal to N numbers of employee[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"] Things i need to copy;[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]Name of the employee from E3 up to the last row with data to be copied at D4 of DTR sample workbook[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Date from H1 up to the the last column with data with 2 column spaces, so H1, J1, L1 etc to be copied from A9 to the last row with data of DTR Sample[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]We have three shifts, 8M, 8N and 8T and blank if dayoff[/TD]
[/TR]
[TR]
[TD="colspan: 5"]I have 4 columns in DTR sample where different conditions are needed for different shifts[/TD]
[/TR]
[TR]
[TD="colspan: 3"]Scheduled word hours[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"]Total Worked Hours[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]Total ND Hours[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Remarks[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8M[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]Needs to have 8 under the scheduled hours column. data will be known from DTR creator H3 inline with the date, next is on J3 etc to be pasted on B9 downwards until there is data available[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Total worked hours is 8 and should be pasted from f9 downwards on DTR Sample[/TD]
[/TR]
[TR]
[TD="colspan: 3"]Total ND hours is blank [/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]Remarks is blank[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8N[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]Needs to have 8 under the scheduled hours column. data will be known from DTR creator H3 inline with the date, next is on J3 etc to be pasted on B9 downwards until there is data available[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Total worked hours is 8 and should be pasted from f9 downwards on DTR Sample[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Total ND hours is 8 and should be pasted from g9 downwards[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Remarks is Night Diff and should be pasted from h9 downwards[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8T[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]Needs to have 8 under the scheduled hours column. data will be known from DTR creator H3 inline with the date, next is on J3 etc to be pasted on B9 downwards until there is data available[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Total worked hours is 8 and should be pasted from f9 downwards on DTR Sample[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Total ND hours is 3 and should be pasted from g9 downwards[/TD]
[/TR]
[TR]
[TD="colspan: 5"]Remarks is Night Diff and should be pasted from h9 downwards[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 5"]After that, the dtr sample will be saveas with the name of the employee being copied then close and then goes next to the next row of the employee name like a loop until there is no more data. [/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"]Thanks in advance![/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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