I
Ihar
Hi
I have a module in a spreadsheet which executes a piece of code, see below
Set wRep = Worksheets("Report to Region")
wRep.Activate
Set R = wRep.Range("A20:A46")
R.Activate
enc = R.Find(What:=sIprojNo, After:=R.Cells(1, 1), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Activate
If enc = False Then
nRows = WorksheetFunction.CountA(R) + 1
R.Cells(nRows, 1) = sIprojNo
R.Cells(nRows, 2).Select
End If
Which works perfectly, later in the same spreadsheet, in a user form, on a
button to save the data that may be captures, I need to do the same data
check and paste the relevant field, if needed to the end of the list so I
copies and pasted the code andit doesnot work, see below
Set wRep = Worksheets("Report to Region")
wRep.Activate
Set R = wRep.Range("A20:A46")
R.Activate
enc = R.Find(What:=sIprojNo, After:=R.Cells(1, 1), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Activate
If enc = False Then
nRows = WorksheetFunction.CountA(R) + 1
R.Cells(nRows, 1) = sIprojNo
R.Cells(nRows, 2).Select
End If
This same code now returns a Run Time Error '91':
Object Variable or With block variable not set
I use Option Explicit so it cant be a variable, what else could it be, any
ideas or suggestions are most welcome.
in both instances, the variables are defined as follows
Dim sIprojNo As String
Dim wRep As Worksheet
Dim R As Range
Dim enc As Boolean
Dim nRows As Integer
I have a module in a spreadsheet which executes a piece of code, see below
Set wRep = Worksheets("Report to Region")
wRep.Activate
Set R = wRep.Range("A20:A46")
R.Activate
enc = R.Find(What:=sIprojNo, After:=R.Cells(1, 1), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Activate
If enc = False Then
nRows = WorksheetFunction.CountA(R) + 1
R.Cells(nRows, 1) = sIprojNo
R.Cells(nRows, 2).Select
End If
Which works perfectly, later in the same spreadsheet, in a user form, on a
button to save the data that may be captures, I need to do the same data
check and paste the relevant field, if needed to the end of the list so I
copies and pasted the code andit doesnot work, see below
Set wRep = Worksheets("Report to Region")
wRep.Activate
Set R = wRep.Range("A20:A46")
R.Activate
enc = R.Find(What:=sIprojNo, After:=R.Cells(1, 1), LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Activate
If enc = False Then
nRows = WorksheetFunction.CountA(R) + 1
R.Cells(nRows, 1) = sIprojNo
R.Cells(nRows, 2).Select
End If
This same code now returns a Run Time Error '91':
Object Variable or With block variable not set
I use Option Explicit so it cant be a variable, what else could it be, any
ideas or suggestions are most welcome.
in both instances, the variables are defined as follows
Dim sIprojNo As String
Dim wRep As Worksheet
Dim R As Range
Dim enc As Boolean
Dim nRows As Integer