automatic number format?

maurot

New Member
Joined
May 4, 2022
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone.
I have a problem, or rather a question...
Let's say I have a cell, A1, whose content is a resolution (ie. 0.1, 0.01, etc - from this I can extract the number of decimals with ROUNDUP(-LOG10(A1); 0))
Then I have various "type" of other cells, namely an input cell (A2), and two other calculated cells (using a formula), one that has zero as a result (A3), and one with, say, '=1/3' (A4).
What I would like to get is that the cell A1 defines how many decimal digits should be shown in cells A2:A4.

Example.
If I wrote 0.1 in A1, and 0.234 in A2, I'd like to see 0.2 in A2, 0.0 in A3, and 0.3 in A4.
And if I wrote 0.01 in A1, I'd like to see 0.23 in A2, 0.00 in A3, and 0.33 in A4.

I've tried to find a solution for each of A2:A3 but without any success.
Anyone know of a possible solution?
Thank you
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Oh, I forgot: and I would like to keep the values in A2:A4 as numbers, because they are necessary elsewhere (something like '=SUM(A2:A4)'). I've seen that using FIXED they are converted into text.
Using General formatting and ROUND the zero value does not work (it shows 0 instead of, 0.0 and 0.00).
If I use FIXED the the numbers are converted into text, and this scramble other calculations.
 
Upvote 0
Welcome to the Forum!

Using conditional formatting or VBA:

Book17
ABCDE
1N3
2
3CF0.2000.3330.000123.456
4
5VBA0.2000.3330.000123.456
Sheet1
Cell Formulas
RangeFormula
C3C3=1/3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:E3Expression=N=4textNO
B3:E3Expression=N=3textNO
B3:E3Expression=N=2textNO
B3:E3Expression=N=1textNO
B3:E3Expression=N=0textNO


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("N")) Is Nothing Then _
        Range("B5:E5").NumberFormat = "#,##0." & Application.Rept("0", Range("N").Value)
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,323
Messages
6,124,246
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top