VBA Code

DFlem

New Member
Joined
Jul 20, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
I currenlty have code that if column I contains a length greater than 2 to duplicate the entire row and paste directly below that line.

However, I could use some help with the other part of the code. I need column J of the new row to equal the cell value in column K of the above (original) row. ONLY on the new duplicate row. I also need the start time and end time in columns M & N to reflect the new quantity hour(s) in the new row. * the new time range should not exceed the original end time.


Here is the current structure of my file:
1678738247635.png


This is how I need the code to look like:

1678738469339.png


Here is my current code:


Sub MealFix()

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("Procore Process Master")
Dim Lastrow As Long
Dim r As Long


Lastrow = ws.Range("B" & Rows.Count).End(xlUp).row

For r = Lastrow To 2 Step -1

If Len(ws.Cells(r, 11).Value) > 2 Then

ws.Cells(r, 1).EntireRow.Offset(1).Insert
ws.Cells(r, 1).EntireRow.Copy Destination:=ws.Cells(r, 1).Offset(1)

End If

Next r

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,214,534
Messages
6,120,080
Members
448,943
Latest member
sharmarick

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