The Convert is only partially fixed

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,484
Office Version
  1. 365
Platform
  1. Windows
I have had it with the Convert function. The units choices are illogical and inconsistent. The latest version at least provides a list of the units, but I still have to scroll down to find the one I want.

Until m$ft really fixes it, (yeah, right), I'm going to use my MyConvert UDF. It just handles days and hours, but I'll add to it as I need more.

VBA Code:
'======================================================================================
'                       My Convert Function

' The built in Convert function uses weird, inconsistent codes for the units.
' MyConvert will take rational ones and call Convert with the ones it wants.

' It uses the UnitsBad2Good subfunction so I have just one place to add units.

' 09/26/21  Created
'======================================================================================
Function MyConvert(pValue As Variant, pUnitsOld As String, pUnitsNew As String) As Variant

Dim UnitsOld As String
Dim UnitsNew As String

UnitsOld = UnitsWeird2Normal(pUnitsOld)
UnitsNew = UnitsWeird2Normal(pUnitsNew)

MyConvert = Application.WorksheetFunction.Convert(pValue, UnitsOld, UnitsNew)

End Function

' This function handles the units conversion
Function UnitsWeird2Normal(pUnitsBad As String) As String

Select Case UCase(pUnitsBad)
  Case "DAYS":  UnitsWeird2Normal = "day"
  Case "HOURS": UnitsWeird2Normal = "hr"
End Select

End Function

And here's a test table:

Fun Facts.xlsx
CDEF
6StartStopConvertMyConvert
701/01/00 07:00 01/01/00 07:00 0.0000 Hours0.0000 Hours
801/01/00 07:00 01/01/00 07:15 0.2500 Hours0.2500 Hours
901/01/00 07:00 01/01/00 09:30 2.5000 Hours2.5000 Hours
1001/01/00 07:00 01/01/00 11:47 4.7833 Hours4.7833 Hours
1101/01/00 07:00 01/01/00 11:47 4.7833 Hours4.7833 Hours
1201/01/00 07:00 01/02/00 23:03 40.0500 Hours40.0500 Hours
temp
Cell Formulas
RangeFormula
E7:E12E7=CONVERT(D7-C7,"day","hr")
F7:F12F7=myCONVERT(D7-C7,"days","hours")


Comments?

PS: Fixed a typo
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I'm confused, your udf just converts 'days' & 'hours' back to 'day' and 'hr' & then runs the excel Convert function that you complained about?

I must be missing something.
 
Upvote 0
I'm confused, your udf just converts 'days' & 'hours' back to 'day' and 'hr' & then runs the excel Convert function that you complained about?

I must be missing something.
Uh-huh, like everything.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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