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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top