Working with fractions

kshora

Board Regular
Joined
Aug 2, 2006
Messages
211
Some months back I did receive the following code, can someone help me, how to use this code, I am not very good with VB or macros. What I want is to convert decimals to fractions (with denominators of 2, 4, 8, 16 or 32)

Help is highly appreciated

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
' note that this implies that in Excel you did Insert | Name | Define...
' and defined a named range «ChangeToFractions» for those cells
' that you want converted from decimals to fractions
const c_strTestRangeName as string = "ChangeToFractions"
Dim rngCell As Range

If Intersect(Target, range(c_strTestRangeName)) Is Nothing Then Exit Sub

application.enableevents = false
for each rngCell in Intersect(Target, range(c_strTestRangeName)).cells
with rngcell
.value = Round(.Value * 32, 0) / 32
end with
next rngcell
application.enableevents = true

End Sub
 
Thanks Erik, it now works great, this will save me enough time to have couple of days off.

I also try to do many things in excel, but when it comes to VB or Macros my brain goes blank.

Thanks once again for your help
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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