Forum Discussion
MargotKloeck
Jul 19, 2022Copper Contributor
Excel other number
Hello, when I write in a cell a number (for example 40), I would like to, not see the number, but 24,84 for example. And this for some other numbers too if this is possible. I don't know where I ...
MargotKloeck
Jul 19, 2022Copper Contributor
Harun24HR Of course, thank you for your answer!
HansVogelaar
Jul 19, 2022MVP
You cannot do this with a formula, for a formula cannot refer to the cell itself. You need VBA code in the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
If Not Intersect(Range("E2:E1000"), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("E2:E1000"), Target)
Select Case rng.Value
Case 40
rng.Value = 24.84 ' VBA uses decimal point, not comma
Case 401
rng.Value = 27.32
Case 25
rng.Value = 31.15
' add other cases as needed
End Select
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
See the attached version of your workbook. It is now a macro-enabled workbook, so you will have to allow macros. Right-click the sheet tab and select 'View Code' from the context menu to inspect and edit the code.