NotaVBAeXpert
New Member
- Joined
- May 4, 2018
- Messages
- 26
Hi All,
So I currently have a testing document which includes testing information. I just got the code to work for inserting rows based on a particular cell directly below that row.
Now i need help figuring out how to copy certain cells from that original row into the new row and loop through my entire sample.
Example; if the row includes letter "T" in column "E", it inserts a new row directly below that line. I would then need to copy data from that row (cells "C" and "F") into the new row (cells "C & D") respectively.
this is the code that I have so far:
Sub InsertRow()
Application.ScreenUpdating = False
Dim Workbook As Workbook
Set Workbook = Workbooks("wbk")
Dim ws1 As Worksheet
Set ws1 = Workbook.Sheets("ws1")
Dim rw, i, newRow As Long
Dim lastRow As Long
' Determine last row with data in Column E
lastRow = ws1.Cells(Rows.Count, "E").End(xlUp).Row
Debug.Print lastRow
' Loop through rows in reverse order
For i = lastRow To 9 Step -1
If ws1.Cells(i, "E").Value = "F" Then
Cells(i, "E").Offset(1, 0).EntireRow.Insert Shift:=xlDown
End If
Next i
Application.ScreenUpdating = True
End Sub
So I currently have a testing document which includes testing information. I just got the code to work for inserting rows based on a particular cell directly below that row.
Now i need help figuring out how to copy certain cells from that original row into the new row and loop through my entire sample.
Example; if the row includes letter "T" in column "E", it inserts a new row directly below that line. I would then need to copy data from that row (cells "C" and "F") into the new row (cells "C & D") respectively.
this is the code that I have so far:
Sub InsertRow()
Application.ScreenUpdating = False
Dim Workbook As Workbook
Set Workbook = Workbooks("wbk")
Dim ws1 As Worksheet
Set ws1 = Workbook.Sheets("ws1")
Dim rw, i, newRow As Long
Dim lastRow As Long
' Determine last row with data in Column E
lastRow = ws1.Cells(Rows.Count, "E").End(xlUp).Row
Debug.Print lastRow
' Loop through rows in reverse order
For i = lastRow To 9 Step -1
If ws1.Cells(i, "E").Value = "F" Then
Cells(i, "E").Offset(1, 0).EntireRow.Insert Shift:=xlDown
End If
Next i
Application.ScreenUpdating = True
End Sub