Fix Negative Decimal Degree to DMS Conversion in Excel VBA
Question details
Correct an Excel VBA macro that converts decimal degrees to degrees, minutes, and seconds.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user converts positive and negative decimal degree values to DMS with an Excel macro.
- Observed behavior
- Negative inputs produce incorrect results, and some positive inputs show incorrect minutes.
Open the workbook in desktop Excel and locate the existing conversion macro in the VBA editor. Enable macros only if you trust the workbook, and save it as an Excel Macro-Enabled Workbook (.xlsm) if you need to keep the code.
Calculate DMS from the Absolute Value in Excel VBA
Use the absolute input for the calculation, then restore the original sign. Rounding the total seconds first also handles carryover into minutes and degrees.
In desktop Excel, open the Developer tab and select Visual Basic. In the editor, select Insert > Module, or open the module containing your existing conversion function.
Paste this function into the module, replacing the old function if it uses the same name: Function DMS(decimalDegrees As Double) As String Dim units As Double Dim degrees As Double Dim minutes As Double Dim seconds As Double Dim signText As String units = Round(Abs(decimalDegrees) * 360000, 0) degrees = Fix(units / 360000) minutes = Fix((units - degrees * 360000) / 6000) seconds = (units - degrees * 360000 - minutes * 6000) / 100 If decimalDegrees < 0 Then signText = "-" DMS = signText & CStr(degrees) & ChrW(176) & " " & _ CStr(minutes) & "' " & Format$(seconds, "00.00") & Chr$(34) End Function
Enter 90.50333333 in cell A2 and =DMS(A2) in another cell. The result should be 90° 30' 12.00". Change A2 to -90.50333333 and confirm the result has a leading minus sign.
Select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) to retain the VBA function.

Work with Degree Conversion Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility, making it easier to move existing workbooks. It does not repair the VBA code in Microsoft Excel.

Frequently Asked Questions
Why does the macro give the wrong DMS result for negative values?
Splitting a negative number directly can produce negative fractional components. Calculate degrees, minutes, and seconds from Abs(decimalDegrees), then add a minus sign to the formatted result when the original input is negative.
How are minutes calculated from decimal degrees?
Subtract the whole degrees from the absolute decimal value and multiply the fractional part by 60. The whole-number portion is the minutes; multiply the remaining fraction by 60 to get seconds.
What happens if seconds round up to 60?
The function rounds the absolute input to hundredths of a second before splitting it into components. This carries the rounded value into the next minute or degree rather than displaying 60 seconds.
Why does Excel show an error for =DMS(A2)?
Check that the function is in a standard VBA module through Developer > Visual Basic and Insert > Module. Open the file in desktop Excel, ensure macros are enabled for a trusted workbook, and save it as .xlsm.




