Hello,
I'm trying to insert a row and copy data into that row below a row in Column A where the cell value is 0. The code I'm using is below and works for the first two row insertions.
However the 3rd and subsequent executions add a row inbetween the 1st Row and the 2nd and not after the last row that contains the value "0" in Column A.
I cannot use the "find last row with data" function as I have data further on in the sheet. Any help you can give is greatly appreciated.
### Code Begins ###
### Code Ends ###
My knowledge of VBA is minimal to be honest and I combined this code from various sources I'd found on the internet (and some very helpful members from these forums @energman58 @Peter SSs) but if anyone has any suggestions I would be very grateful.
Thank you for reading and any possible help you can give.
I'm trying to insert a row and copy data into that row below a row in Column A where the cell value is 0. The code I'm using is below and works for the first two row insertions.
However the 3rd and subsequent executions add a row inbetween the 1st Row and the 2nd and not after the last row that contains the value "0" in Column A.
I cannot use the "find last row with data" function as I have data further on in the sheet. Any help you can give is greatly appreciated.
### Code Begins ###
Code:
Option Explicit
Option Compare Text
Sub InsertRow()
Dim rFind As Long
'On Error Resume Next
'Selects the 'Project Phase' from the 'Cover Sheet'
Sheets("Cover Sheet").Select
Range("B27").Select
Application.CutCopyMode = False
Selection.Copy
'Selects the 'Format Control' Sheet and 'Project Phase' Cell
Sheets("Format Control").Select
Range("B4").Select
'Pastes the 'Project Phase' from the 'Cover Sheet'
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Selects Row To Be Copied
Rows("4:4").Select
'Copies Entire Row Selected Above
Selection.Copy
'Selects the 'Environment Information' Sheet
Sheets("Environment Information").Select
'Looks for the value '0' in Column A from Cell A5 and down.
rFind = Columns("A:A").Find(What:="0", After:=Range("A5"), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
If rFind > 0 Then Rows(rFind + 1).Insert xlShiftDown
Cells(rFind + 1, 2).Select
End Sub
### Code Ends ###
My knowledge of VBA is minimal to be honest and I combined this code from various sources I'd found on the internet (and some very helpful members from these forums @energman58 @Peter SSs) but if anyone has any suggestions I would be very grateful.
Thank you for reading and any possible help you can give.
Last edited by a moderator: