Run-time Error error '6' when trying to return multiple values from function using user-defined type

Heli_Guy

New Member
Joined
Jul 31, 2015
Messages
6
I followed this post in order to return two values from a function: http://www.geeksengine.com/article/vba-function-multiple-values2.html

Here is the code I used:
Public Type Waypoint
Lat As Double
Lon As Double
End Type

Dim LatLon As Waypoint

LatLon = UTMToLatLon("N", 17, 534150, 4836410) 'Run-time Error error '6' when this line runs

Function UTMToLatLon(Hemisphere As String, Zone As Integer, Easting As Integer, Northing As Integer) As Waypoint
Dim LatLon As Waypoint
LatLon.Lat = 43.679919
LatLon.Lon = -80.576323

UTMToLatLon = LatLon
End Function

Any ideas what I'm doing wrong?

This is the error I get when the code tried to call the function call:
sQKKxBW.png
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Solved!

The problem was that Easting and Northing values were beyond the capacity of an integer. Changed them to Double and the error no longer occurs.
 
Upvote 0

Forum statistics

Threads
1,215,357
Messages
6,124,482
Members
449,165
Latest member
ChipDude83

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