ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error 91 - Sometimes happens, sometimes it doesnt. (https://www.excelbanter.com/excel-programming/331801-error-91-sometimes-happens-sometimes-doesnt.html)

BerkshireGuy[_2_]

Error 91 - Sometimes happens, sometimes it doesnt.
 
Ok, sounds like an Almond Joy commerical.

Anyways, I have the following code and sometimes I get an error 91 and
sometimes I dont.

Any ideas?

objWkb.Worksheets("Sorted Rankings").Range("A1:B1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With


STEVE BELL

Error 91 - Sometimes happens, sometimes it doesnt.
 
You can make this easier:
=======================================
With Worksheets("Sorted Rankings").Range("A1:B1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
===========================
And you may not need the lines = False

I'm not sure what error91 is. But your code will fail if the worksheet is
not the active sheet.
The above code doesn't care. It also works faster by not selecting
anything.
--
steveB

Remove "AYN" from email to respond
"BerkshireGuy" wrote in message
oups.com...
Ok, sounds like an Almond Joy commerical.

Anyways, I have the following code and sometimes I get an error 91 and
sometimes I dont.

Any ideas?

objWkb.Worksheets("Sorted Rankings").Range("A1:B1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With




BerkshireGuy[_2_]

Error 91 - Sometimes happens, sometimes it doesnt.
 
Steve,

Ok, I modified as suggested now I am getting Method Worksheet of Global
failed.

Thanks

Brian


Leith Ross[_40_]

Error 91 - Sometimes happens, sometimes it doesnt.
 

Hello BerkshireGuy,

Error 91 - "Object variable or With Block variable not set." The With
Block looks fine. I suspect somewherelse in your code objWkb is not
being set.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=379162


STEVE BELL

Error 91 - Sometimes happens, sometimes it doesnt.
 
My bad....

Change Worksheets(.....) to Sheets(....)

--
steveB

Remove "AYN" from email to respond
"BerkshireGuy" wrote in message
ups.com...
Steve,

Ok, I modified as suggested now I am getting Method Worksheet of Global
failed.

Thanks

Brian




Tom Ogilvy

Error 91 - Sometimes happens, sometimes it doesnt.
 
With objWkb.Worksheets("Sorted Rankings").Range("A1:B1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With

--
Regards,
Tom Ogilvy

"BerkshireGuy" wrote in message
oups.com...
Ok, sounds like an Almond Joy commerical.

Anyways, I have the following code and sometimes I get an error 91 and
sometimes I dont.

Any ideas?

objWkb.Worksheets("Sorted Rankings").Range("A1:B1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With





All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com