Option Explicit
Function MètresIm(ByVal Impé)
Dim Pouces As Double, TSpl() As String
If TypeOf Impé Is Range Then Impé = Impé.Value
Select Case VarType(Impé)
Case vbString
TSpl = Split(Impé, "'")
If UBound(TSpl) = 1 Then
Pouces = 12 * Val(TSpl(0)): Impé = TSpl(1)
End If
TSpl = Split(Impé, """")
If UBound(TSpl) = 1 Then
TSpl = Split(TSpl(0))
Pouces = Pouces + Val(TSpl(0))
If UBound(TSpl) = 1 Then
TSpl = Split(TSpl(1), "/")
If UBound(TSpl) = 1 Then Pouces = Pouces + Val(TSpl(0)) / Val(TSpl(1))
End If: End If
Case vbDouble: Pouces = Impé
Case Else: MètresIm = CVErr(xlErrValue): End Select
MètresIm = 0.0254 * Pouces
End Function
Function Impérial(ByVal m As Double) As String
Dim Pouces As Double, Pieds As Integer, N&, D%, U$
Pouces = Int(16 * m / 0.0254 + 0.5) / 16
If Pouces >= 12 Then
Pieds = Int(Pouces / 12)
Impérial = Pieds & "'"
Pouces = Pouces - 12 * Pieds
End If
If Pouces >= 1 Then
Impérial = Impérial & Int(Pouces)
Pouces = Pouces - Int(Pouces)
U = """": End If
If Pouces > 0 Then
N = 16 * Pouces: D = 16
While N Mod 2 = 0: N = N \ 2: D = D \ 2: Wend
If Right$(Impérial, 1) > "'" Then Impérial = Impérial & " "
Impérial = Impérial & N & "/" & D
U = """": End If
Impérial = Impérial & U
End Function