|
Format Cells as a Fraction in Excel Number Formatting
This free Excel macro will automatically format a selected cell or many selected cells in the Fraction number format in Excel. The Fraction number format is the appropriate format to use in order to correctly display fractions in Excel.
This Excel macro is great for automating repetitive formatting tasks or for quickly formatting a large selection of cells in Excel. This macro work on the cells, rows, or columns which have been highlighted before the macro is run.
Where to install the macro: Module
Excel Macro to Format Cells as a Fraction in Excel Number Formatting
Sub Format_Cell_Fraction()
Selection.NumberFormat = "# ?/?"
End Sub
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
Hello everybody,
I am trying to do a simple thing.
I have a number say 35 in A1 and in B1 I divide it by 2 so i get 17.5
I use format cell number to fraction display which gives me 17 1/2
Desired output :I want the fraction to display as 17 1/2" (where " is the sign for inches)
Question #1
Is there a simple formula to do this
I tried = A1 & " " ".. but is removes the fraction formatting which is not acceptable
and displays 17.5"
I tried Text(A1,"??").. where ?? I am not sure what to enter for fraction display
Any help will be much appreciated
Thanks
In Excel 2007, I have a cell in Sheet1 with the named range of "currency" and data validation set to list, with currency symbols listed in the drop down. On Sheet1 I used conditional formatting to change the number format of certain cells to match the currency symbol selected in the drop down list using,for example, =currency="$" and it works fine. On Sheet2 I use the same conditional format statement and when I select a currency from the drop down on Sheet1 it will change the format once but if I select a different currency it won't change the number format. What's weird, is if not only do I set the conditional formatting to change the number format but the color of the cell as well, the cell color will change but the number format will not. Is this just a bug in excel or am I doing something wrong?
Thanks
Hello,
I am running Excel 2003 and I wish to apply conditional formatting to only cells with format Number. Does anyone knows an easy way of doing this or a VBA code for it?
I have tried on my own to write a code , but as I am new to VBA , I can't figure out how to make it work . The code supposed to compare all the numeric values from an uknown number of columns with numeric values from column B row by row and Bold the ones greater. The number of columns and rows is uknown because the data will be exported from another software to Excel , so bassically I wish to format a woorkbook to automatically do that.
The code is below:
VB:
Sub ConvertsFontStyletoBold()
Dim Count As Integer
Dim Count1 As Integer
Dim nr1 As Range
Dim nr2 As Range
Dim nr3 As Range
Dim nr4 As Range
Dim nr5 As Range
Dim nr6 As Range
Dim nr7 As Range
Dim nr8 As Range
Set nr1 = Range("A65536").End(xlUp)
nr1.Select
Set nr2 = Range("a1").End(xlToRight)
nr2.Select
Count = Range("A1", nr2).Columns.Count - 1
Set nr3 = Range("A1", nr1.Offset(0, Count))
nr3.Name = "Data"
nr3.Select
Set nr4 = Range("B65536").End(xlUp)
nr4.Select
Set nr5 = Range("B7", nr4)
nr5.Select
Set nr6 = Range("D7").End(xlToRight)
nr6.Select
Set nr7 = Range("D65536").End(xlUp)
nr7.Select
Count = Range("D7", nr6).Columns.Count - 1
Set nr8 = Range("D7", nr7.Offset(0, Count))
nr8.Name = "Values"
nr8.Select
For Each r In nr8.Rows
i = r.Row
r.Select
If IsNumeric(Cells(r)) = True And r.xlCellValue > nr5.xlCellValue = True Then
cell.Font.Bold = True
End If
Next r
End Sub
If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines
Thank you very much for any help received.
Hi, i want to know if there is any way i can type in my cell so that a fraction such as "8 1/2" appears to be "8 with normal font size and the 1/2 to be smaller font size.
i'm now just entering 8.5 and the out come is 8 1/2, but i wanna make it so the 1/2 is smaller.
Thanx in adavance for ur reply.
Hi I need a simple script in VBA I am using excel 2003. What I am need is in a column have 100-24 this will be print in another column like 100.75 i.e., 100+(24/32)
same as 100-32+ is 101.0219 ie., 100+((32+.7)/32)
if its 3digt 100-256 it should be 101.00 ie., 100+(256/256).
I wrote like this but its not working for three dig. Kindly advice
thanks,
Public Sub FindandReplace()
Dim temp As Variant
Dim first, second As Integer
For Row = 1 To 10
If (InStr((Sheet2.Cells(Row, 2).value), "-")) Then
temp = split((Sheet2.Cells(Row, 2).value), "-")
If (Len(temp(1)) = 1) Or (Len(temp(1)) = 2) Then
first = CInt(temp(0))
second = CInt(temp(1))
Sheet2.Cells(Row, 3).value = first + (second / 32)
End If
If (Len(temp(1)) = 3) Then
first = CInt(temp(0))
second = CInt(temp(1))
Sheet2.Cells(Row, 3).value = first + (second / 256)
If Sheet2.Cells.find(What:="+", After:=Cells(Row, 2), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate Then
Sheet2.Cells(Row, 3).value = first + ((second + 0.7) / 32)
End If
End If
End If
Next
End Sub
I have a formula in VBA that is calculated and displayed in a Label,
and then inserted into a cell,
I cannot get the darned thing to display as a Fraction or get it
formatted into the cell as a fraction
Here is the formula
Private Sub ListBox2_Change()
If ListBox2.Value = "H.W.R." Then
Label17.Caption = TextBox4.Text - 1 / 8
Else
Label17.Caption = TextBox4.Text + 1 / 8
End If
End Sub
Any Ideas
I would like to have fractions only shown in increments of 1/16. I don't want to see 1/5, 1/10, 1/12, 1/25, etc.
Only want to see 1/16, 1/8, 3/16, 1/4, 5/16, 3/8, etc.
Fractions round up to the nearest 1/16.
Is this possible?
I'm wanting to give plant operators access to a spreadsheet which they can input a number and receive an output in a format they can equate to a distance on their tape measure.
Thanks
I created a work sheet that works with feet and inches. Right now, I keep the feet in one cell and th4e fractional inches in another. When I try and add the two cells into a single entry, the fraction format is converted back to decimal. I tried treating the fraction as text but it still gets coverted.
Is there any way of formatting a cell to show a percentage with a fraction? For example, I'd like to show: 3 1/3%, 1 2/3%, 2 1/2%, etc.
I'm showing data to a client who will pull out his calculator and add up the decimals on his calculator and be unhappy that the numbers don't add up to 100%.
I can force the output by using TEXT() or multiple columns, but ideally, I'd like a custom format if possible.
Thank you.
Hi
I have a custom format to display a fraction or odds to be precise in a cell. The format is ###/###.
However, I can't seem to get a textbox to display the value in this format.
I've tried:
Code:
enter_odds.TextBox1.Value = Format(rCell.Offset(, 7).Value, "###/##")
Any ideas?
Thanks
|
|