View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1510_] Rick Rothstein \(MVP - VB\)[_1510_] is offline
external usenet poster
 
Posts: 1
Default Calculation With A Macro

Just a note.

VBA is pretty forgiving. You can concatenate text with numbers and still
end up
with text.

.Range("B" & CStr(X))
could be written as:
.Range("B" & X)

(same in the =sum() portion, too.)

I like:
.cells(x,"B")
though.

I'm guessing that VB is less forgiving?????


No, actually, the guts of VBA and compiled VB are the same; so, in this
case, VB would be as forgiving. In the compiled VB world, it is considered
(and please don't take this the wrong way) poor programming practice to let
VB handle the conversions automatically when you know in advance what the
data type should be. Over there, VB's underlying data type coercions are
called "evil type coercions" and are to be avoided whenever possible. In
addition, not omitting default object properties (the Value property of a
Range being an example), expressly declaring variable types and avoiding
Variants whenever possible are also considered good programming practice as
well... three more things which seem to be laxly adhered to in the Excel
community. So, when you see me doing any of these things (such as expressly
using the CStr function as you pointed out), it will simply be a case of
"old habits die hard".

Rick