Cyberpunk001
New Member
- Joined
- Aug 27, 2018
- Messages
- 13
Good day,
I need VBA code to automatically insert a row below or inbetween rows based on criteria.
In the example below, I need code to run row by row to check if the "OVER" column >0,
if that case is true, it will check 3 conditions:
1) Check the "HOURS" column for the max hours such as 10.5
2) Check the EMP ID column for a unique ID such as 0001
3) Check the WEEKDAY column for values not equal to 7
Based on these three conditions, it will insert a row below the 10.5 HOURS column in this example. (see A5:D5)
Once the new row is inserted, it will copy over all the data in each column from the row above, except for the "HOURS" column,
instead it will take the OVER value which in 0001's case is 2.5 and put that in the HOURS column for the new row.
[TABLE="width: 500"]
<tbody>[TR]
[TD]EMP ID(A1)[/TD]
[TD]HOURS[/TD]
[TD]WEEKDAY[/TD]
[TD]OVER[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]1[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]10[/TD]
[TD]2[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]10.5[/TD]
[TD]3[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]NEW 0001 A5[/TD]
[TD]2.5 OVER B5[/TD]
[TD]3 C5[/TD]
[TD]2.5 D5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]4[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]6[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]7[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]10[/TD]
[TD]2[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9.25[/TD]
[TD]3[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9.25[/TD]
[TD]4[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9[/TD]
[TD]5[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9[/TD]
[TD]6[/TD]
[TD]1.5 (D12)[/TD]
[/TR]
</tbody>[/TABLE]
The actual file has thousands of rows of data such as above, with many more columns of data, each EMP ID is in such a format as above.
Any help will be appreciated
I need VBA code to automatically insert a row below or inbetween rows based on criteria.
In the example below, I need code to run row by row to check if the "OVER" column >0,
if that case is true, it will check 3 conditions:
1) Check the "HOURS" column for the max hours such as 10.5
2) Check the EMP ID column for a unique ID such as 0001
3) Check the WEEKDAY column for values not equal to 7
Based on these three conditions, it will insert a row below the 10.5 HOURS column in this example. (see A5:D5)
Once the new row is inserted, it will copy over all the data in each column from the row above, except for the "HOURS" column,
instead it will take the OVER value which in 0001's case is 2.5 and put that in the HOURS column for the new row.
[TABLE="width: 500"]
<tbody>[TR]
[TD]EMP ID(A1)[/TD]
[TD]HOURS[/TD]
[TD]WEEKDAY[/TD]
[TD]OVER[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]1[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]10[/TD]
[TD]2[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]10.5[/TD]
[TD]3[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]NEW 0001 A5[/TD]
[TD]2.5 OVER B5[/TD]
[TD]3 C5[/TD]
[TD]2.5 D5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]4[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]6[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0001[/TD]
[TD]9[/TD]
[TD]7[/TD]
[TD]2.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]10[/TD]
[TD]2[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9.25[/TD]
[TD]3[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9.25[/TD]
[TD]4[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9[/TD]
[TD]5[/TD]
[TD]1.5[/TD]
[/TR]
[TR]
[TD]0002[/TD]
[TD]9[/TD]
[TD]6[/TD]
[TD]1.5 (D12)[/TD]
[/TR]
</tbody>[/TABLE]
The actual file has thousands of rows of data such as above, with many more columns of data, each EMP ID is in such a format as above.
Any help will be appreciated