Search: | |||||

| ||||

Home » Forum » MS Office | RSS Feeds |

Could i have some input on doing something ... but it seems so simple and i

cant work out .. what i am doing wrong...

APART from trying to use a bit code for a function for converting mm's in to

inches and then display in a text format of xx ft - xx" - variable (sub

division of inches ie. 1/16th ,1/8th , 1/4, 10th etc which is passed a

variable)

The code for the original was found on a website.

I now need a routine that does the reverse

Take a mm's figure split in to meters, cms and mms and then display this a

text value xx m's xx . xx cms

But i wish to have the function to be able to automatically adjust from an

optional variable of showing it in

The meters cms and mm's format

The cms and mm format

And mm's format

I just cant get it in to my head.. but perhaps i should be looking a fresh

at coding rather than altering the original code.

Please find below the code of the function which takes mm and convert to the

imperial string

'\ This function converts a decimal number of inches to a text string like

5'-6 1/2"

Function CFeet(Decimal_MMs, Optional

Enter_16_32_64_Etc__To_Round_Inches_To__Fraction_Of_Inch)

'\ These variables are used to convert the decimal inches to the number

'\ of fractional units. For example 6" would convert to 96 16ths

Dim iNumUnits As Long '\ converted value = 96 in example

Dim iUnit As Double '\ unit used to convert = 1/16 in example

'\ These varibles are used to hold calculated values that will become

'\ part of the text string

Dim iFeet As Integer

Dim iInches As Integer

Dim dFraction As Double

Dim sFtSymbol As String

Application.Volatile True 'forces recalculation

'\ These variables are used to assign shorter names to input values

Dim vVal As Variant

Dim vDenominator As Variant

'\ First we assign shorter names

'\ Convertin The value passed to function in to inches

'\ Value of mm is Decimal_mm multiplied by inches value 0.0394

vVal = Decimal_MMs * 0.0394

'vval converted to a decimal_inches

vDenominator = Enter_16_32_64_Etc__To_Round_Inches_To__Fraction_Of_Inch

'\ If no denominator value was supplied, we will round to 1/9999 of inch

If IsMissing(vDenominator) Then

iUnit = 1 / 9999

Else

iUnit = 1 / vDenominator

End If

'\ Now we calculate the number of fractional units in the input value

'\ Example 6 inches = 96 16ths

iNumUnits = (vVal / iUnit)

'\ We prepare each part of text string

iFeet = Fix(iNumUnits / (12 / iUnit))

iInches = Fix((iNumUnits Mod (12 / iUnit)) * iUnit)

dFraction = (iNumUnits Mod (1 / iUnit)) * iUnit

If iFeet <> 0 Then sFtSymbol = "'-"

'\ Finally we format and return text string

CFeet = Application.Text(iFeet, "##") & sFtSymbol &

Application.Text(iInches + dFraction, "# ##/##\""")

End Function

Didn't find what you were looking for?
Find more on rewriting a function for metric instead of imperial
Or get search suggestion and latest updates.

Related Topics:

- Using Boolean logic instead of IF, AND, OR functions
- Wait function and Invisible function
- Wait function and Invisible function
- Url Rewrite
- RAW and LONG RAW instead of CLOB and BLOB in TimesTen
- smaller number possible instead of the maximum
- Using QueryTable instead of OpenText with a file that has fixed width
- Java client instead JavaScript and AJAX, Flash
- How can I call the function TotalPrice within another function?
- help on functions
- Problems with XL's 'MATCH' function
- Excel won't calculate my function
- User Function - is optional calculation possibe?
- Automatic update of Function return value.
- String-Split Function parameter "compare"
- function as argument
- Need to create function smiliar to DMAX
- Logistic Regression (Statistical Functions)
- Wierd problem in VBA code re Mid function
- function question
- function to change the color of the cell
- User Defined Function didn't work
- How does the Worksheets function work?
- Converting Date functions
- user-designed Excel math functions