Fraction Format with VBA

ToddG

Board Regular
Joined
Sep 28, 2004
Messages
82
I thought I could get away with a custom cell format to accomplish this but it doesn't appear that it will work that way.

This is the code I tried to do this with:

<font face=Courier New><SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range("D:D")
<SPAN style="color:#00007F">If</SPAN> c.Value = "Total" <SPAN style="color:#00007F">Then</SPAN>
c.Offset(0, 1) = Format(Cells(c.Row, "b"), "# ##/##") & " x " & Format(Cells(c.Row, "c"), "# ##/##")
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> c</FONT>

But I am not ending with fractions so obviously my formatting is incorrect.

Any input would be appreciated
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
Hello Todd,
It's hard to tell your exact intent in that post, but perhaps this will help?
Code:
For Each c In Range("D:D")
  If c.Value = "Total" Then
    With c(1, 2)
      .Value = Cells(c.Row, 2) * Cells(c.Row, 3)
      .NumberFormat = "# ?/?"
    End With
  End If
Next c

{EDIT:}
Multiply column B times column C and put the result in column E formatted as a fraction?
 

ToddG

Board Regular
Joined
Sep 28, 2004
Messages
82
Hi HalfAce,

No, actually i'm joining the value in column B, an "x", and the value in column C.

for example: 4 13/16 x 1 1/4 should be the result.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,498
Messages
5,832,055
Members
430,109
Latest member
govivek

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
Top