Functions in VBA

  • Thread starter Thread starter Murthy
  • Start date Start date
M

Murthy

In a particular situation, I wanted to calculate several values on a
worksheet through a macro.

But, I find that some of the vital functions are not available in VBA. For
example - LEN() is not available in VBA. Is there any workaround for this?

Second question - again on fundamental VBA.
A1=10
A2=15
B1=5
B2=20

Sometimes, when I check through VBA
if Range("A1")+Range("A2") = Range("B1")+Range("B2")
this condition evaluates to false, because either of the values would be
something like 25.000000000000000178 or something like that.
(Then I check the values in the individual cells and they are exactly the
same as shown above)

How to overcome this over-precision problem?

Regards,
Murthy
 
Hi

You missed to inform us, which version of Excel do you use!
1. From MS Help (Excel2000):
Len Function
Returns a Long containing the number of characters in a string or the number
of bytes required to store a variable.
Syntax
Len(string | varname)
(I.e. to get the length of value in cell, you have to store it to variable
at first)

2. To avoid problems caused by the way the numbers are stored in excel, you
can use rounding:
If Round(Range("A1")+Range("A2"),10)=Round(Range("B1")+Range("B2"),10)
 
Thanks, Arvi.

I am using Excel2000. The LEN function I asked for is with reference to VBA

Murthy
 
Hi

So where is the problem?

MyVar=Range("A1").Value
MyVarLen=Len(MyVar)

or
MyVar=1234
MyVarLen=Len(MyVar)
 
Back
Top