Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Use variable for a range in WITH block

Greetings all. I have the following....

With Sheets("MacroDEA").Range("C2:" &
Sheets("MacroDEA").Cells(LastInputRow, ThetaCol - 1).Address)
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
End With

It works fine. However, this is just one of many format changes I need to
make. Can I declare a range variable, set it = to the range in question,
then use the variable in the With block, so the code is not so cumbersome?
This is what I am trying, but it does not work

Dim MyRange as Range
MyRange = Sheets("MacroDEA").Range("C2:" &
Sheets("MacroDEA").Cells(LastInputRow, ThetaCol - 1).Address)

With MyRange
.the rest of it
End with

Any ideas? I've also tried using a string and variant data types, but
nothing seems to work. Thank you.l

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Use variable for a range in WITH block

Use

Set MyRange = Sheets(...).Range(...)

The "Set" is vital.

Sam

"Greg Snidow" wrote:

Greetings all. I have the following....

With Sheets("MacroDEA").Range("C2:" &
Sheets("MacroDEA").Cells(LastInputRow, ThetaCol - 1).Address)
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
End With

It works fine. However, this is just one of many format changes I need to
make. Can I declare a range variable, set it = to the range in question,
then use the variable in the With block, so the code is not so cumbersome?
This is what I am trying, but it does not work

Dim MyRange as Range
MyRange = Sheets("MacroDEA").Range("C2:" &
Sheets("MacroDEA").Cells(LastInputRow, ThetaCol - 1).Address)

With MyRange
.the rest of it
End with

Any ideas? I've also tried using a string and variant data types, but
nothing seems to work. Thank you.l

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Use variable for a range in WITH block

Thank you Sam. I knew I had done it before, but I could not find it.
Anyhow, it works like a charm, and I'll never forget that again.

"Sam Wilson" wrote:

Use

Set MyRange = Sheets(...).Range(...)

The "Set" is vital.

Sam

"Greg Snidow" wrote:

Greetings all. I have the following....

With Sheets("MacroDEA").Range("C2:" &
Sheets("MacroDEA").Cells(LastInputRow, ThetaCol - 1).Address)
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
End With

It works fine. However, this is just one of many format changes I need to
make. Can I declare a range variable, set it = to the range in question,
then use the variable in the With block, so the code is not so cumbersome?
This is what I am trying, but it does not work

Dim MyRange as Range
MyRange = Sheets("MacroDEA").Range("C2:" &
Sheets("MacroDEA").Cells(LastInputRow, ThetaCol - 1).Address)

With MyRange
.the rest of it
End with

Any ideas? I've also tried using a string and variant data types, but
nothing seems to work. Thank you.l

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
Need help with Error 'object variable or with block variable not set' Francois via OfficeKB.com Excel Programming 5 April 30th 07 03:05 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 09:28 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"