#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 189
Default question on VB code

hi,
can anybody explain what the difference is between these two expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default question on VB code

Assuming that you have not declared the variables, and so they assume
variant type, then

- the first creates a range object variable pointing at the range in
question. Through this variable, you can access any the range properties,
including the values

- the second just loads the values in the range into an array variable, so
only giving access to those values.

They do different things, so using one in place of the other will probably
not do what is required.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"peyman" wrote in message
...
hi,
can anybody explain what the difference is between these two expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default question on VB code

The set command is used to assign a value to an object of some type,
document, PivotTable, Workbook, Worksheet, ToolBar and Range are just a few
of the object one can assign to an object variable.

Failure to assign an object variable a value without the use of SET will
produce an error.

I would suggest that at the top of the module you enter Option Explicit on a
line by itself to insure that all variables must be declared before assigning
them a value of some type.


--
Kevin Backmann


"peyman" wrote:

hi,
can anybody explain what the difference is between these two expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default question on VB code

On Oct 22, 12:35 pm, peyman wrote:
hi,
can anybody explain what the difference is between these two expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx


The second statement uses the default property of Range, which is
Value.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 189
Default question on VB code

hi Bob,
could you please let me know what other range properties besides the value
can be allocated to myRange in case I use the "set"?

"Bob Phillips" wrote:

Assuming that you have not declared the variables, and so they assume
variant type, then

- the first creates a range object variable pointing at the range in
question. Through this variable, you can access any the range properties,
including the values

- the second just loads the values in the range into an array variable, so
only giving access to those values.

They do different things, so using one in place of the other will probably
not do what is required.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"peyman" wrote in message
...
hi,
can anybody explain what the difference is between these two expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default question on VB code

All of them,

myRange.Interior.Colorindex = 37

myRange.Font.Name = "Verdana"

etc.

Look up Range in VBA help and click on the Properties link to see them

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"peyman" wrote in message
...
hi Bob,
could you please let me know what other range properties besides the value
can be allocated to myRange in case I use the "set"?

"Bob Phillips" wrote:

Assuming that you have not declared the variables, and so they assume
variant type, then

- the first creates a range object variable pointing at the range in
question. Through this variable, you can access any the range properties,
including the values

- the second just loads the values in the range into an array variable,
so
only giving access to those values.

They do different things, so using one in place of the other will
probably
not do what is required.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"peyman" wrote in message
...
hi,
can anybody explain what the difference is between these two
expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx






  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 189
Default question on VB code

appreciate it.

"Bob Phillips" wrote:

All of them,

myRange.Interior.Colorindex = 37

myRange.Font.Name = "Verdana"

etc.

Look up Range in VBA help and click on the Properties link to see them

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"peyman" wrote in message
...
hi Bob,
could you please let me know what other range properties besides the value
can be allocated to myRange in case I use the "set"?

"Bob Phillips" wrote:

Assuming that you have not declared the variables, and so they assume
variant type, then

- the first creates a range object variable pointing at the range in
question. Through this variable, you can access any the range properties,
including the values

- the second just loads the values in the range into an array variable,
so
only giving access to those values.

They do different things, so using one in place of the other will
probably
not do what is required.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"peyman" wrote in message
...
hi,
can anybody explain what the difference is between these two
expressions:
set myRange=activesheet.range("A10:B20")
myRange=activesheet.range("A10:B20")
and what will happen if we use the codes in place of each other?
thanx







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
Another code question M&M[_2_] Excel Discussion (Misc queries) 3 August 9th 07 10:00 PM
VB Code Question Stan Excel Discussion (Misc queries) 2 May 2nd 07 10:13 PM
VB Code Question Stan Excel Discussion (Misc queries) 6 April 30th 07 11:27 PM
VBA code question JEV Excel Discussion (Misc queries) 2 March 1st 07 06:02 PM
Easy VB code question Anthony Excel Discussion (Misc queries) 2 July 8th 05 08:45 PM


All times are GMT +1. The time now is 04:04 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"