Hi All,
I've been using the following code successfully and this is it's function:
It copies some values from one sheet to another, then looks for a value (0,1 or 2) in Column A of the ("Environment Information") worksheet and then copies a specified row from the ("Format Control"). sheet under the row it found this value in last on the ("Environment Information") worksheet. :
I now want to adapt this code to use on another sheet, simply to look for the last value of "3" in column A on the active sheet, when it's found copy row 19 from the ("Format Control") worksheet and paste it one row below the row that had the value "3" in it. When I use the adapted code below I seem to get this error:
Adapted code with code that becomes highlighted when debugging in VBA in bold:
I'm thoroughly stumped as this code was provided by another member on here and I thought I had it understood but it would seem this has confused me.
Any help would be gratefully appreciated. I'm looking for someone to point out my mistake and highlight how I can resolve to I can learn as well as fix my code
Thank you for your time.
Mark.
I've been using the following code successfully and this is it's function:
It copies some values from one sheet to another, then looks for a value (0,1 or 2) in Column A of the ("Environment Information") worksheet and then copies a specified row from the ("Format Control"). sheet under the row it found this value in last on the ("Environment Information") worksheet. :
Code:
Option Explicit
Sub Add_Ad_Hoc_Server()
Dim rng As Range
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("Format Control").Range("C4").Value = _
Sheets("Cover Sheet").Range("B27").Value
With Sheets("Environment Information")
.Unprotect
Set rng = .Columns("A").Find(What:="0", After:=.Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlPrevious, _
MatchCase:=False, SearchFormat:=False)
Sheets("Format Control").Rows(4).Copy
rng.Offset(1).EntireRow.Insert
rng.Offset(1, 3).Select
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowInsertingRows:=True, AllowDeletingRows:=True
End With
ActiveWindow.ScrollRow = 1
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I now want to adapt this code to use on another sheet, simply to look for the last value of "3" in column A on the active sheet, when it's found copy row 19 from the ("Format Control") worksheet and paste it one row below the row that had the value "3" in it. When I use the adapted code below I seem to get this error:
Code:
Microsoft Visual Basic
Run-time error '91':
Object variable or With block variable not set
Adapted code with code that becomes highlighted when debugging in VBA in bold:
Code:
Option Explicit
Sub Add_Line_Pre_Deployment_Preparation()
Dim rng As Range
'Application.DisplayAlerts = False
'Application.ScreenUpdating = False
With Sheets("Release Plan Ver Draft 0.1")
.Unprotect
Set rng = .Columns("A").Find(What:="3", After:=.Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlPrevious, _
MatchCase:=False, SearchFormat:=False)
Sheets("Format Control").Rows(19).Copy
[B]rng.Offset(1).EntireRow.Insert[/B]
rng.Offset(1, 3).Select
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, _
AllowInsertingRows:=True, AllowDeletingRows:=True
End With
' ActiveWindow.ScrollRow = 1
'Application.DisplayAlerts = True
'Application.ScreenUpdating = True
End Sub
I'm thoroughly stumped as this code was provided by another member on here and I thought I had it understood but it would seem this has confused me.
Any help would be gratefully appreciated. I'm looking for someone to point out my mistake and highlight how I can resolve to I can learn as well as fix my code
Thank you for your time.
Mark.
Last edited: