Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default With statement

Is it possible to have nested With statements ??

Problem I have - VBA application that refers back and forth between
workbook / worksheets. I have an 'exterior' With statement like this...

With Workbooks(ThisworkBook).Sheets(MySheet.Name)
' (some code)

Workbooks(AnotherWorkbook).Sheets(3).Activate
With Workbooks(AnotherWorkbook).Sheets(3)

' interior code here will make references to inner With
.Range("someRange").Value = ...

End With
End With

I want to refer to a range defined in the outer With ...is that possible
(and how ?)

Appreciate any advice.

Thanks,
Chad

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default With statement

You can, but the object within the secondary With must be part of the
primary with object, or totally independent. You cannot refer to both with
objects from within either structure using the dot notation, one would have
to be fully qualified.

So you cannot do what you are trying to do.
--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ChadF" wrote in message
...
Is it possible to have nested With statements ??

Problem I have - VBA application that refers back and forth between
workbook / worksheets. I have an 'exterior' With statement like this...

With Workbooks(ThisworkBook).Sheets(MySheet.Name)
' (some code)

Workbooks(AnotherWorkbook).Sheets(3).Activate
With Workbooks(AnotherWorkbook).Sheets(3)

' interior code here will make references to inner With
.Range("someRange").Value = ...

End With
End With

I want to refer to a range defined in the outer With ...is that possible
(and how ?)

Appreciate any advice.

Thanks,
Chad



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default With statement

Thanks Bob, that's pretty much what I figured. In the example I provided, I
wound up simply defining a worksheet variable at the top of my subroutine and
referenced it that way ... reads like :

Dim aWS as Worksheet
....

Set aWS = Workbooks(AnotherWorkbook).Sheets(3)
With Workbooks(ThisworkBook).Sheets(MySheet.Name)
' (some code)

aWS.Activate
aWS.Range("B1:B10").Value = .Range("someRange").Value

' (and so forth)

End With

Appreciate your help.
Chad


"Bob Phillips" wrote:

You can, but the object within the secondary With must be part of the
primary with object, or totally independent. You cannot refer to both with
objects from within either structure using the dot notation, one would have
to be fully qualified.

So you cannot do what you are trying to do.
--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ChadF" wrote in message
...
Is it possible to have nested With statements ??

Problem I have - VBA application that refers back and forth between
workbook / worksheets. I have an 'exterior' With statement like this...

With Workbooks(ThisworkBook).Sheets(MySheet.Name)
' (some code)

Workbooks(AnotherWorkbook).Sheets(3).Activate
With Workbooks(AnotherWorkbook).Sheets(3)

' interior code here will make references to inner With
.Range("someRange").Value = ...

End With
End With

I want to refer to a range defined in the outer With ...is that possible
(and how ?)

Appreciate any advice.

Thanks,
Chad




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default With statement

That's how I do it also.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ChadF" wrote in message
...
Thanks Bob, that's pretty much what I figured. In the example I provided,

I
wound up simply defining a worksheet variable at the top of my subroutine

and
referenced it that way ... reads like :

Dim aWS as Worksheet
...

Set aWS = Workbooks(AnotherWorkbook).Sheets(3)
With Workbooks(ThisworkBook).Sheets(MySheet.Name)
' (some code)

aWS.Activate
aWS.Range("B1:B10").Value = .Range("someRange").Value

' (and so forth)

End With

Appreciate your help.
Chad


"Bob Phillips" wrote:

You can, but the object within the secondary With must be part of the
primary with object, or totally independent. You cannot refer to both

with
objects from within either structure using the dot notation, one would

have
to be fully qualified.

So you cannot do what you are trying to do.
--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ChadF" wrote in message
...
Is it possible to have nested With statements ??

Problem I have - VBA application that refers back and forth between
workbook / worksheets. I have an 'exterior' With statement like

this...

With Workbooks(ThisworkBook).Sheets(MySheet.Name)
' (some code)

Workbooks(AnotherWorkbook).Sheets(3).Activate
With Workbooks(AnotherWorkbook).Sheets(3)

' interior code here will make references to inner With
.Range("someRange").Value = ...

End With
End With

I want to refer to a range defined in the outer With ...is that

possible
(and how ?)

Appreciate any advice.

Thanks,
Chad






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
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM
Help please, IF statement/SUMIF statement Brad_A Excel Worksheet Functions 23 January 11th 05 02:24 PM


All times are GMT +1. The time now is 10:17 PM.

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

About Us

"It's about Microsoft Excel"