Create a marcro that changes number of decimal places in a field according to specified criteria

H

Hayley Middleton

Hi people, hope you can help me

I need a macro to do the following:

1. A1 contains a value - 2 (which determines the number of decimal places
2. A2 contains a value - 10
3. A3 gives the results - i.e A1 is number of decimal places for A2 therefore = 1.0

Can this be done

Thank you for your help

Hayley
 
P

Pete McCosh

Hayley,

it can be done, but is there any reason why this would
have to be done with a macro?

The easiest way would just be to have a formula dividing
A2 by 10 to A1-th power like this:

=A2/(10^A1)

The equivalent in VBA would be something like:

Cells(3,1).value = cells(2,1).value/(10 ^ Cells(1,1).value)

Cheers, Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top