Passing a string argument into a numerical function in EXCEL VBA?
-
I'm new to Excel VBA, I'm writing a function in excel vba that will take the number from a text cell and return a number. here is my code: Function coordist(Lat As String) As Long Dim DLat As Long Dim DLong As Long Dim DDeg As Long, DMin As Long, DSec As Long DDeg = WorksheetFunction.Value(Left(Lat, 2)) DMin = WorksheetFunction.Value(Mid(Lat, 4, 2)) DSec = WorksheetFunction.Value(Mid(Lat, 7, 4)) DLat = DDeg + (DMin / 60) + (DSec / 3600) 'DLong = Value(Left(Lon, 2)) + Value(Mid(Lon, 4, 2)) / 60 + Value(Mid(Lon, 7, 4)) / 3600 coordist = DMin End Function When I run this code I get an error that says " a value used in the formula is of a wrong data type" Can any one help with this?
-
Answer:
change: DDeg = WorksheetFunction.Value(Left(Lat, 2)) DMin = WorksheetFunction.Value(Mid(Lat, 4, 2)) DSec = WorksheetFunction.Value(Mid(Lat, 7, 4)) to DDeg = Val(Left(Lat, 2)) DMin = Val(Mid(Lat, 4, 2)) DSec = Val(Mid(Lat, 7, 4))
Golden Axe at Yahoo! Answers Visit the source
Related Q & A:
- How to replace a string inside of a Word Document?Best solution by Stack Overflow
- How to access a nested function from another nested function in javascript?Best solution by devarticles.com
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
- Can being a notary without passing the Bar Exam get a decent paying job?Best solution by Yahoo! Answers
- How do I write a Counter Argument for my persuasive essay?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.