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

Why does it matter where you put the "=" in a macro (see line 3). I am range
valuing cells that contain the "If" formula. In the following code:

For Each cll In Range("v10:v44")
If Left(cll.Formula, 3) = "=IF" Then
cll.Value = cll
End If
Next

why does this range value my cells but this next code does not:

For Each cll In Range("v10:v44")
If Left(cll.Formula, 3) = "=IF" Then
cll = cll.Value
End If
Next

Why is cll.Value=cll not the same as cll=cll.Value

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default = positioning

The problem arises when you don't declare cll, or in other words, when cll
is declared as a variant.

In the second case, VBA evaluates first

"cll.Value"

where cll is a Range object, and then assigns whatever its value is (a
Double, or a String for example) to a "new" cll variable, not the original
Range object.

In the first case, VBA evaluates first

cll

and since at this point, it is still a Range object, VBA uses the default
property, which is .Value, so that line is equivalent to

cll.Value = cll.Value

however, since you're explicitly calling a property of the object, VBA
doesn't create the "new" variable, but instead uses the same reference to
the Range, therefor changing the formulas into the values, as you would
expect.

Bottom line, always declare your variables, and put "Option Explicit" at the
top of your modules.

--
Regards

Juan Pablo González

"snax500" wrote in message
om...
Why does it matter where you put the "=" in a macro (see line 3). I am

range
valuing cells that contain the "If" formula. In the following code:

For Each cll In Range("v10:v44")
If Left(cll.Formula, 3) = "=IF" Then
cll.Value = cll
End If
Next

why does this range value my cells but this next code does not:

For Each cll In Range("v10:v44")
If Left(cll.Formula, 3) = "=IF" Then
cll = cll.Value
End If
Next

Why is cll.Value=cll not the same as cll=cll.Value

Thanks



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
Forms Positioning DUknow Excel Discussion (Misc queries) 0 May 6th 09 01:29 AM
POSITIONING A TOOLBAR FARAZ QURESHI Excel Discussion (Misc queries) 0 September 14th 07 05:26 AM
Comment Box Positioning Q Sean Excel Worksheet Functions 1 March 17th 07 05:03 PM
AutoShape Positioning? Ken Excel Discussion (Misc queries) 2 February 8th 05 11:45 PM
msgbox positioning Wild Bill[_2_] Excel Programming 4 August 28th 03 06:08 PM


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