VBA & Macro Problems

Fix Negative Decimal Degree to DMS Conversion in Excel VBA

Rana GarciaRana Garcia Nov 25, 2026 870 views

Question details

Correct an Excel VBA macro that converts decimal degrees to degrees, minutes, and seconds.

Fix Negative Decimal Degree to DMS Conversion in Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

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.

2
Add the corrected 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

3
Test positive and negative values

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.

4
Save the workbook

Select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) to retain the VBA function.

Calculate DMS from the Absolute Value in Excel VBA
Why the minutes are 30: The fractional degree is approximately 0.50333333. Multiplying it by 60 gives approximately 30.2 minutes: 30 whole minutes and 0.2 minute, or 12 seconds.
Free Microsoft Office alternative

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.

Use worksheet formulas to work with decimal degree dataOpen and edit Microsoft Excel formats such as XLSXNavigate spreadsheets with a familiar interfaceUse a lightweight office suite with free core features
microsoft office alternative - wps office

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.