VBA & Macro Problems

Fix Excel VBA Error 13 When Mapping Coordinates

Aamir Naveed AkramAamir Naveed Akram Dec 2, 2026 868 views

Question details

The user needs to prevent a VBA type mismatch when passing spreadsheet coordinates to a mapping routine.

Fix Excel VBA Error 13 When Mapping Coordinates
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A VBA macro reads latitude and longitude values from worksheet cells and sends them to a mapping routine.
Observed behavior
VBA Error 13 can occur when a coordinate cell contains an incompatible value, such as text, a blank, an error value, or an unexpected symbol.
Before you start

Identify the worksheet and columns containing latitude and longitude, and check a few cells for error values, symbols, and decimal separators. Open the workbook in Excel and make sure you can access its VBA editor.

Solution 1Recommended

Validate and Convert Coordinates Before Mapping

Use this approach when the mapping macro reads coordinates from cells that may contain invalid or incompatible values.

1
Open the macro

In Excel, press Alt+F11 or open Developer > Visual Basic. Locate the procedure that reads the coordinate cells and calls the mapping routine.

2
Check the column order

Inspect the worksheet headers and the macro's cell references. Confirm which column contains latitude and which contains longitude, and check the parameter order expected by the mapping routine.

3
Validate each pair of values

Before converting a cell value, check IsError and IsEmpty. Reject blank strings and use IsNumeric before calling CDbl. For example, adapt this procedure to your worksheet and mapping call: Sub CheckCoordinates() Dim ws As Worksheet Dim r As Long, lastRow As Long Dim latValue As Variant, lonValue As Variant Dim latitude As Double, longitude As Double Set ws = ThisWorkbook.Worksheets("Sheet1") lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row For r = 2 To lastRow latValue = ws.Cells(r, "A").Value lonValue = ws.Cells(r, "B").Value If IsError(latValue) Or IsError(lonValue) Then GoTo NextRow If IsEmpty(latValue) Or IsEmpty(lonValue) Then GoTo NextRow If Trim(CStr(latValue)) = "" Or Trim(CStr(lonValue)) = "" Then GoTo NextRow If Not IsNumeric(latValue) Or Not IsNumeric(lonValue) Then GoTo NextRow latitude = CDbl(latValue) longitude = CDbl(lonValue) If latitude < -90 Or latitude > 90 Then GoTo NextRow If longitude < -180 Or longitude > 180 Then GoTo NextRow ' Call your mapping routine here with latitude and longitude. NextRow: Next r End Sub

4
Adapt and test the code

Replace Sheet1 and columns A and B with your actual worksheet and coordinate columns. Replace the comment with your mapping routine call, then run the macro from Developer > Macros on rows containing valid and invalid coordinates.

5
Correct invalid cells

Return to the worksheet and fix skipped rows as needed. Remove unexpected symbols, correct cell errors, and use numeric decimal separators compatible with the system's regional settings before rerunning the macro.

Validate and Convert Coordinates Before Mapping
Decimal separators matter: IsNumeric and CDbl interpret numeric text using regional settings. Verify the source format before changing separators; replacing commas or periods blindly can change a coordinate's value.
Free Microsoft Office alternative

Work With Coordinate Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. Its Excel format support helps you move coordinate data between suites, although it does not fix an error in Microsoft Excel VBA.

Review and edit latitude and longitude columns in WPS SpreadsheetOpen and save Microsoft Excel formats such as XLSXUse a familiar spreadsheet interface for an easier transitionWork with a free, lightweight office suite
QA img-9

Frequently Asked Questions

Why does a coordinate cell cause VBA Error 13?

The macro may be assigning a cell error, text, or another incompatible value to a numeric variable. Check the cell with IsError and IsNumeric before converting it with CDbl.

How do I handle blank coordinate cells?

Check IsEmpty for truly empty cells and check for a blank string after ruling out error values. Skip the row or ask the user to correct it before calling the mapping routine.

Can a decimal separator cause a type mismatch?

Yes. Numeric text may use a comma or period that does not match the system's regional settings. Check the source format and test IsNumeric before using CDbl.

Which data type should I use for latitude and longitude?

Use Double variables for converted coordinates. Read cell values into Variant variables first so the macro can check for cell errors and other invalid values before conversion.

How can I check whether latitude and longitude are reversed?

Compare the worksheet headers and cell references with the mapping routine's parameter order. Latitude normally ranges from -90 to 90, while longitude ranges from -180 to 180; values within both ranges still require a column-order check.