VBA code to automatically insert a row below based on criteria

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 :)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,816
Messages
6,181,143
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