vba copy/pase (multiple) rows below/other sheet based on criteria (networkdays)

hansgrandia

Board Regular
Joined
Jan 10, 2015
Messages
53
Hello,

In order to compare data, it's necessary for me to copy rows based on the number of networkdays (which is calculated). So if networkdays is 2, another additional row is needed below the original row. If networkdays is 10, there are 9 additional rows required below that specific row (or perhaps on other sheet). Preferable with calculating one additional working in column 8 (Date_Begin). This for all rows in the sheet. No action required if Networkdays is 1.

Does a person see the key for this problem? Thank you, Hans Grandia (Netherlands)

VBA Code:
Sub insert_rows_based_Workdays()

Dim LastRow As Long
Dim Networkday As Long

'insert column for calculation working days
Columns("H").Insert
Range("H1").Value = "Working Days"

'Determine Last_Row
With ActiveSheet
    LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
End With

'Formula for working_days
For i = 2 To LastRow
Cells(i, 8).Formula = Application.WorksheetFunction.NetworkDays(Cells(i, 6), Cells(i, 7))
Next i

Columns("H:H").Select
Selection.NumberFormat = "General"

'Copy lines based on number of Networkdays
For i = 2 To LastRow
NetworkDays = Cells(i, 8).Value

'?

End Sub
 

Attachments

  • Picture.png
    Picture.png
    24.4 KB · Views: 18

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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