Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Object variable or With block variable not set

I have looked thru the other postings for "error 91 Object variable or With
block variable not set", but have not been able to fiqure out what I need to
change in my code. I have a spread sheet that has pop up form that presents
records from range security_name as a list, and the user can highligth one of
the records from this list to delete, this deletes corresponding records from
other sheets in the workbook as well. This works about 50% of the time, but
the other 50% it does not. The bug is the error 91 mentioned above, and it
affects (or not) the same records. Any help is appreciated.

Code from the popup form:

Private Sub UserForm_Initialize()
Dim MyArray()

MyArray() = (Sheet10.Range("SecurityName").Value)
Me.ListBox1.List = MyArray
End Sub

Private Sub cmdEnter_Click()
Dim N As Integer
Dim Str As String

If Me.ListBox1.Value < "" Then
Str = Me.ListBox1.Value 'Assign String value of selected listbox1
option
'Delete Security from Weightage table
Set LastRow = Sheet4.Range("SecurityName_Weightage").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Core Model
Set LastRow = Sheet10.Range("SecurityName").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 1
Set LastRow = Sheet3.Range("SecurityName_1").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 2
Set LastRow = Sheet5.Range("SecurityName_2").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 3
Set LastRow = Sheet6.Range("SecurityName_3").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 4
Set LastRow = Sheet7.Range("SecurityName_4").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 5
Set LastRow = Sheet8.Range("SecurityName_5").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 6
Set LastRow = Sheet9.Range("SecurityName_6").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Record Transaction in Transaction Sheet
Set LastRow = Sheet2.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).EntireRow.Insert
LastRow.Offset(1, 0).Value = Date
LastRow.Offset(1, 1).Value = "Remove Security"
'Record Security name only, without stock symbol
LastRow.Offset(1, 2).Value =
Application.WorksheetFunction.Replace(Arg1:=Str, Arg2:=(InStr(Str, "(")),
Arg3:=8, Arg4:="")
'Removing Security from ListBox1 and Opening Messagebox to notify
user operation has taken palce
N = Me.ListBox1.ListIndex
Me.ListBox1.RemoveItem (N)
MsgBox (" The Security Named '" & Str & "' Removed")
Unload Me
Else
MsgBox ("Please Select a Security to Remove")


End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Object variable or With block variable not set

Hi

As you don't state which line is throwing the error, it's not easy to help
you.

A guess would be that the selected string isn't found. To verify that try to
enter the line below in the immediate window in debug mode, when the error
has emerged.

If that's the case you will get the error when trying to delete a row. You
will need something like this:

If not LastRow is Nothing then
LastRow.EntireRow.Delete
Else
'Str wasn't found!
End if

Hopes this helps.

---
Per

"Imran J Khan" skrev i meddelelsen
...
I have looked thru the other postings for "error 91 Object variable or With
block variable not set", but have not been able to fiqure out what I need
to
change in my code. I have a spread sheet that has pop up form that
presents
records from range security_name as a list, and the user can highligth one
of
the records from this list to delete, this deletes corresponding records
from
other sheets in the workbook as well. This works about 50% of the time,
but
the other 50% it does not. The bug is the error 91 mentioned above, and it
affects (or not) the same records. Any help is appreciated.

Code from the popup form:

Private Sub UserForm_Initialize()
Dim MyArray()

MyArray() = (Sheet10.Range("SecurityName").Value)
Me.ListBox1.List = MyArray
End Sub

Private Sub cmdEnter_Click()
Dim N As Integer
Dim Str As String

If Me.ListBox1.Value < "" Then
Str = Me.ListBox1.Value 'Assign String value of selected listbox1
option
'Delete Security from Weightage table
Set LastRow = Sheet4.Range("SecurityName_Weightage").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Core Model
Set LastRow = Sheet10.Range("SecurityName").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 1
Set LastRow = Sheet3.Range("SecurityName_1").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 2
Set LastRow = Sheet5.Range("SecurityName_2").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 3
Set LastRow = Sheet6.Range("SecurityName_3").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 4
Set LastRow = Sheet7.Range("SecurityName_4").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 5
Set LastRow = Sheet8.Range("SecurityName_5").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 6
Set LastRow = Sheet9.Range("SecurityName_6").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Record Transaction in Transaction Sheet
Set LastRow = Sheet2.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).EntireRow.Insert
LastRow.Offset(1, 0).Value = Date
LastRow.Offset(1, 1).Value = "Remove Security"
'Record Security name only, without stock symbol
LastRow.Offset(1, 2).Value =
Application.WorksheetFunction.Replace(Arg1:=Str, Arg2:=(InStr(Str, "(")),
Arg3:=8, Arg4:="")
'Removing Security from ListBox1 and Opening Messagebox to notify
user operation has taken palce
N = Me.ListBox1.ListIndex
Me.ListBox1.RemoveItem (N)
MsgBox (" The Security Named '" & Str & "' Removed")
Unload Me
Else
MsgBox ("Please Select a Security to Remove")


End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Object variable or With block variable not set

I believe that when you used the Find method like this:

Set LastRow = Sheet4.Range("SecurityName_Weightage").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete

And Str is not found it will throw the error for Object Variable not set.
Maybe if you use an if statement like this:

Set LastRow = Sheet4.Range("SecurityName_Weightage").Find(Str,
LookIn:=xlValues)
If Not LastRow Is Nothing Then
LastRow.EntireRow.Delete
Else
MsgBox "Str Not Found"
End If

It is the only thing that I can see that might cause the message to display.




"Imran J Khan" wrote:

I have looked thru the other postings for "error 91 Object variable or With
block variable not set", but have not been able to fiqure out what I need to
change in my code. I have a spread sheet that has pop up form that presents
records from range security_name as a list, and the user can highligth one of
the records from this list to delete, this deletes corresponding records from
other sheets in the workbook as well. This works about 50% of the time, but
the other 50% it does not. The bug is the error 91 mentioned above, and it
affects (or not) the same records. Any help is appreciated.

Code from the popup form:

Private Sub UserForm_Initialize()
Dim MyArray()

MyArray() = (Sheet10.Range("SecurityName").Value)
Me.ListBox1.List = MyArray
End Sub

Private Sub cmdEnter_Click()
Dim N As Integer
Dim Str As String

If Me.ListBox1.Value < "" Then
Str = Me.ListBox1.Value 'Assign String value of selected listbox1
option
'Delete Security from Weightage table
Set LastRow = Sheet4.Range("SecurityName_Weightage").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Core Model
Set LastRow = Sheet10.Range("SecurityName").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 1
Set LastRow = Sheet3.Range("SecurityName_1").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 2
Set LastRow = Sheet5.Range("SecurityName_2").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 3
Set LastRow = Sheet6.Range("SecurityName_3").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 4
Set LastRow = Sheet7.Range("SecurityName_4").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 5
Set LastRow = Sheet8.Range("SecurityName_5").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Delete Security from Model 6
Set LastRow = Sheet9.Range("SecurityName_6").Find(Str,
LookIn:=xlValues)
LastRow.EntireRow.Delete
'Record Transaction in Transaction Sheet
Set LastRow = Sheet2.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).EntireRow.Insert
LastRow.Offset(1, 0).Value = Date
LastRow.Offset(1, 1).Value = "Remove Security"
'Record Security name only, without stock symbol
LastRow.Offset(1, 2).Value =
Application.WorksheetFunction.Replace(Arg1:=Str, Arg2:=(InStr(Str, "(")),
Arg3:=8, Arg4:="")
'Removing Security from ListBox1 and Opening Messagebox to notify
user operation has taken palce
N = Me.ListBox1.ListIndex
Me.ListBox1.RemoveItem (N)
MsgBox (" The Security Named '" & Str & "' Removed")
Unload Me
Else
MsgBox ("Please Select a Security to Remove")


End If
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Getting inconsistent Error 91-Object variable or With block variable not set mfq Excel Programming 0 December 14th 05 06:08 PM
Run-time Error'91: Object variable or With block variable not set DynamiteSkippy Excel Programming 4 September 26th 05 07:47 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 01:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"