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

Hi,

The following is a code from a module. I have declared the worksheets
as Module level variables.


Option Explicit
Option Private Module
Dim Sourcesheet As Worksheet
Dim Destinationsheet1 As Worksheet
Dim Destinationsheet2 As Worksheet
--------------------------------------------------------------------------
Sub AddInvoice
Set Sourcesheet = Worksheets("Invoice")
Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet2 = Worksheets("Invoices")
UnProtectSourcesheet
UnProtectDestinationsheet1
UnProtectDestinationsheet2

While both the Sourcesheet and Destinationsheet2 variables are set and
available later, the Destinationsheet1 returns the "Object variable
not set" error once control goes out of the sub. Immediately after
the Set line I tested it in the Immediate window and the
Destinationsheet1.name returns Worksheets("Transactions") . However
as soon as the control goes out of the AddInvoice sub, the other two
variables continue to return values but Destinationsheet1.name shows
"object not set". I am clueless.

Thanks in Advance for the help.

Regards,
Raj
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Object variable not set error

Not knowing what the rest of your code is, I would suggest that you get rid
of the 'Option Private Module' line or at least rem it out and try again.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Raj" wrote:

Hi,

The following is a code from a module. I have declared the worksheets
as Module level variables.


Option Explicit
Option Private Module
Dim Sourcesheet As Worksheet
Dim Destinationsheet1 As Worksheet
Dim Destinationsheet2 As Worksheet
--------------------------------------------------------------------------
Sub AddInvoice
Set Sourcesheet = Worksheets("Invoice")
Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet2 = Worksheets("Invoices")
UnProtectSourcesheet
UnProtectDestinationsheet1
UnProtectDestinationsheet2

While both the Sourcesheet and Destinationsheet2 variables are set and
available later, the Destinationsheet1 returns the "Object variable
not set" error once control goes out of the sub. Immediately after
the Set line I tested it in the Immediate window and the
Destinationsheet1.name returns Worksheets("Transactions") . However
as soon as the control goes out of the AddInvoice sub, the other two
variables continue to return values but Destinationsheet1.name shows
"object not set". I am clueless.

Thanks in Advance for the help.

Regards,
Raj
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Object variable not set error

On Mar 20, 12:29*am, Gary Brown <junk_at_kinneson_dot_com wrote:
Not knowing what the rest of your code is, I would suggest that you get rid
of the 'Option Private Module' line or at least rem it out and try again.
--
Hope this helps. *
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown

"Raj" wrote:
Hi,


The following is a code from a module. I have declared the worksheets
as Module level variables.


Option Explicit
Option Private Module
Dim Sourcesheet As Worksheet
Dim Destinationsheet1 As Worksheet
Dim Destinationsheet2 As Worksheet
--------------------------------------------------------------------------
Sub AddInvoice
Set Sourcesheet = Worksheets("Invoice")
Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet2 = Worksheets("Invoices")
UnProtectSourcesheet
UnProtectDestinationsheet1
UnProtectDestinationsheet2


While both the Sourcesheet and Destinationsheet2 variables are set and
available later, the Destinationsheet1 returns the "Object variable
not set" error once control goes out of the sub. *Immediately after
the Set line I tested it in the Immediate window and the
Destinationsheet1.name returns *Worksheets("Transactions") . However
as soon as the *control goes out of the AddInvoice sub, the other two
variables continue to return values but Destinationsheet1.name shows
"object not set". I am clueless.


Thanks in Advance for the help.


Regards,
Raj
.


Tried that. The variable is not retaining the worksheet.

The code is for this: The Invoice sheet has Invoice data that is to be
written to the destination sheets which are protected. The code after
setting the sheets proceeds to unprotect the sheets . It is failing at
this point for Destinationsheet2 while it is working fine for the
other two sheets.

Regards,
Raj.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Object variable not set error

Change the code to refer to the worksheet by it's codename:

'Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet1 = Worksheets(Sheet2) 'your codename

If this works, then there is some mismatch in the spelling of the name
"Transactions".

Mike F
"Raj" wrote in message
...
On Mar 20, 12:29 am, Gary Brown <junk_at_kinneson_dot_com wrote:
Not knowing what the rest of your code is, I would suggest that you get
rid
of the 'Option Private Module' line or at least rem it out and try again.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown

"Raj" wrote:
Hi,


The following is a code from a module. I have declared the worksheets
as Module level variables.


Option Explicit
Option Private Module
Dim Sourcesheet As Worksheet
Dim Destinationsheet1 As Worksheet
Dim Destinationsheet2 As Worksheet
--------------------------------------------------------------------------
Sub AddInvoice
Set Sourcesheet = Worksheets("Invoice")
Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet2 = Worksheets("Invoices")
UnProtectSourcesheet
UnProtectDestinationsheet1
UnProtectDestinationsheet2


While both the Sourcesheet and Destinationsheet2 variables are set and
available later, the Destinationsheet1 returns the "Object variable
not set" error once control goes out of the sub. Immediately after
the Set line I tested it in the Immediate window and the
Destinationsheet1.name returns Worksheets("Transactions") . However
as soon as the control goes out of the AddInvoice sub, the other two
variables continue to return values but Destinationsheet1.name shows
"object not set". I am clueless.


Thanks in Advance for the help.


Regards,
Raj
.


Tried that. The variable is not retaining the worksheet.

The code is for this: The Invoice sheet has Invoice data that is to be
written to the destination sheets which are protected. The code after
setting the sheets proceeds to unprotect the sheets . It is failing at
this point for Destinationsheet2 while it is working fine for the
other two sheets.

Regards,
Raj.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Object variable not set error

I think you meant:

Set Destinationsheet1 = Sheet2 'your codename

Where Sheet2 is the codename for a sheet in the same workbook as the code.



Mike Fogleman wrote:

Change the code to refer to the worksheet by it's codename:

'Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet1 = Worksheets(Sheet2) 'your codename

If this works, then there is some mismatch in the spelling of the name
"Transactions".

Mike F
"Raj" wrote in message
...
On Mar 20, 12:29 am, Gary Brown <junk_at_kinneson_dot_com wrote:
Not knowing what the rest of your code is, I would suggest that you get
rid
of the 'Option Private Module' line or at least rem it out and try again.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown

"Raj" wrote:
Hi,


The following is a code from a module. I have declared the worksheets
as Module level variables.


Option Explicit
Option Private Module
Dim Sourcesheet As Worksheet
Dim Destinationsheet1 As Worksheet
Dim Destinationsheet2 As Worksheet
--------------------------------------------------------------------------
Sub AddInvoice
Set Sourcesheet = Worksheets("Invoice")
Set Destinationsheet1 = Worksheets("Transactions")
Set Destinationsheet2 = Worksheets("Invoices")
UnProtectSourcesheet
UnProtectDestinationsheet1
UnProtectDestinationsheet2


While both the Sourcesheet and Destinationsheet2 variables are set and
available later, the Destinationsheet1 returns the "Object variable
not set" error once control goes out of the sub. Immediately after
the Set line I tested it in the Immediate window and the
Destinationsheet1.name returns Worksheets("Transactions") . However
as soon as the control goes out of the AddInvoice sub, the other two
variables continue to return values but Destinationsheet1.name shows
"object not set". I am clueless.


Thanks in Advance for the help.


Regards,
Raj
.


Tried that. The variable is not retaining the worksheet.

The code is for this: The Invoice sheet has Invoice data that is to be
written to the destination sheets which are protected. The code after
setting the sheets proceeds to unprotect the sheets . It is failing at
this point for Destinationsheet2 while it is working fine for the
other two sheets.

Regards,
Raj.


--

Dave Peterson


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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Run-time error 91: Object Variable or With block variable not set Ayo Excel Programming 1 August 17th 09 11:29 PM
Runtime Error 91 Object variable or With block variable not set. Tim Excel Programming 9 June 5th 08 10:03 PM
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 12:20 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"