Forum

Notifications
Clear all

Control cell number format with VBA

2 Posts
2 Users
0 Reactions
131 Views
(@uhsoccer)
Posts: 1
New Member
Topic starter
 

I have users who need to switch between Inch and Metric. They may switch back and forth in a session, depending on the customer desired format

When they want to switch to Inches the VBA code uses

        Range("B3:C8,B13:C18,B23:C28").Select  '  on sheet Dimensions
        Selection.NumberFormat = "# ??/??"

When switching to Metric

        Range("B3:C8,B13:C18,B23:C28").Select  '  Last Run/Defaults
        Selection.NumberFormat = "#0.00"

Again they may switch back to Inches, etc

The problem is the display as shown below for Inches, which is expected to the nearest 1/16

 2 1/2  should be displayed, but 2 8/16 is shown (the 8/16 looks stupid due to the "# ??/?? setting)

 2 3/4  should be displayed, but 2 12/16 is shown  (12/16 looks dumb as well, again the # ??/?? setting)

 How do I allow "to the nearest 1/16" get have it display a user friendly equivalent

Remember, users need to be able to switch back and forth between the unit systems!

 
Posted : 14/02/2020 2:27 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Henry,

I answered this qs yesterday when you emailed us.  Did you not get that reply?

Use the CONVERT function

https://www.myonlinetraininghub.com/excel-convert-function

and you can then format the number as a fraction

https://support.office.com/en-us/article/display-numbers-as-fractions-0121ecac-1773-4f2d-8cd3-7db51fd83b77

To achieve the switching between imperial and metric, use a value in a cell, or a dropdown, or radio buttons.

Regards

Phil

 
Posted : 14/02/2020 8:58 pm
Share: