Displaying cell values in formula

David2

New Member
Joined
Jan 13, 2018
Messages
39
I would like to display my excel formula with data (not cell references).

Here I've created some visually poor attempt at this.

8nQoy

https://i.imgur.com/JQm9g1g.png

Ideally, Excel would display my formula (with raw data, in a fraction form as shown above) and in another cell show the actual result.

Preferably this would be done without macros.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Welcome to the Forum!

Perhaps something along these lines:

E2: ="=(" & TEXT(A2,"$#,##0.00")& " + " &TEXT(B2,"$#,##0.00")&") / "&C2


Book1
ABCDE
1DataResultFormula
2$1.00$2.502$1.75=($1.00 + $2.50) / 2
3$4.00$5.006$1.50=($4.00 + $5.00) / 6
Sheet1
 
Last edited:
Upvote 0
Stephen thanks for the welcome and your help. Worked great!


Just one more question - is it possible to have the E cell display the formula as a "real fraction" (where the dividend is actually situated over the divisor, like in any math book)?

https://imgur.com/a/5L8bM
 
Upvote 0
A couple of possibilities:

1. Excel formula (a bit clunky looking):

E2: ="(" & TEXT(A2,"$#,##0.00")& " + " &TEXT(B2,"$#,##0.00")&")"&CHAR(10)&REPT("-",LEN("(" & TEXT(A2,"$#,##0.00")& " + " &TEXT(B2,"$#,##0.00")&")"))&CHAR(10)&C2

2. You need VBA to put more than one format into a cell whose result is determined by formula, so for example:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range, r As Range
    Dim s As String
    
    Set rng = Intersect(Target, Range("MyData"))
    If rng Is Nothing Then Exit Sub
    Application.EnableEvents = False
    
    For Each r In rng.Rows
        s = "(" & Format(Range("A" & r.row).Value, "$#,##0.00") & " + " & Format(Range("B" & r.row).Value, "$#,##0.00") & ")"
        With Range("F" & r.row)
            .Font.Underline = False
            .Value = s & Chr(10) & Range("C2").Value
            .Characters(1, Len(s)).Font.Underline = True
        End With
    Next r
    
    Application.EnableEvents = True

End Sub

F2 and F3 don't display properly below, but the numerators are actually underlined so they look quite neat:

Book1
ABCDEF
1DataResultFormulaVBA
2$1.00$2.502$1.75($1.00 + $2.50) --------------- 2($1.00 + $2.50) 2
3$4.00$5.006$1.50($4.00 + $5.00) --------------- 6($4.00 + $5.00) 6
Sheet1
 
Last edited:
Upvote 0
Oops, correction:

Code:
'This line
.Value = s & Chr(10) & Range("C2").Value
'should be
.Value = s & Chr(10) & Range("C" & r.row).Value
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,016
Members
448,936
Latest member
almerpogi

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