Runtime error 91

Pobek

Board Regular
Joined
Jul 7, 2015
Messages
99
I have a model that performs an automatic hide of a formular bar depending on what cells you pick (password entering cells and so on). There is a function that does this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("Tauthcod")) Is Nothing Then
Application.DisplayFormulaBar = False
Else
Application.DisplayFormulaBar = True
End If
End If
End Sub

The model works and no problem. However when I send the file to someone else and that person tries to enable editing, i get the runtime error 91 saying "Object Variable or With block variable not set". When you debug, the second line (1st IF statement) gets highlighted.

Any quick and permanent fixes? ... silver-bullet anyone?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I am not sure, but typically, the first line would look like this:
Code:
[COLOR=#333333]If Target.Count = 1 Then
instead of this:
[/COLOR]
Code:
If Selection.Count = 1 Then[/COLOR]

One typically uses "Target" and not "Selection" in Event Procedure code.
 
Upvote 0
By definition, Target is the range that was selected that triggers the Worksheet_SelectionChange event procedure code to run.
In Worksheet_Change event procedure code, Target is the range that was changed that triggers it to run.

Here is a good write-up on Event Procedures. Chip gets into Target a bit in the "Sample Event Procedure" section.
http://www.cpearson.com/excel/events.aspx
 
Upvote 0
By definition, Target is the range that was selected that triggers the Worksheet_SelectionChange event procedure code to run.
In Worksheet_Change event procedure code, Target is the range that was changed that triggers it to run.

Here is a good write-up on Event Procedures. Chip gets into Target a bit in the "Sample Event Procedure" section.
http://www.cpearson.com/excel/events.aspx



Thanks for that!! Ill have a look!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top