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
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,002
Messages
5,575,478
Members
412,667
Latest member
rpbenz
Top