Victor D


Hello,

I have the folowing code:

 

Public Function DgrMinSec2DecDgr(Angle As Double) As Double
' * --------------------------------------------------------
' * Program not yet working
' * --------------------------------------------------------
' * Variables
Dim grd As Integer
Dim min As Integer
Dim sec As Integer
Dim calc As Double
' * Values
grd = Angle \ 1
calc = (Angle - grd) * 100
min = calc \ 1
calc = (calc - min) * 100
sec = calc \ 1
DgrMinSec2DecDgr = grd + (min / 60) + (sec / 3600)
DgrMinSec2DecDgr = Round(DgrMinSec2DecDgr, 4) ' should I round this result 
' * Write - problem in writing in cell
'Debug.Print Round(DgrMinSec2DecDgr, 4)
'ActiveCell.Formula = "Write" & DgrMinSec2DecDgr
ActiveCell.Select: Selection.FormulaR1C1 = calc '"Write Sel" '& DgrMinSec2DecDgr
End Function
 
I will be extremely gratefull for your answers.
Thank you.
V.



Re: Writing result in Excel

Joe Dawson


Hi,

I am not sure what you are looking to return in the cell, but I think you may just need to change the variable type of the function to variant. As is, you have declared it as Double and that does not jive with adding text to the output.

Joe



Public Function DgrMinSec2DecDgr(Angle As Double) As Variant
' * Variables
Dim grd As Integer
Dim min As Integer
Dim sec As Integer
Dim calc As Double
' * Values
grd = Angle \ 1
calc = (Angle - grd) * 100
min = calc \ 1
calc = (calc - min) * 100
sec = calc \ 1

DgrMinSec2DecDgr = grd + (min / 60) + (sec / 3600)
DgrMinSec2DecDgr = "Write Sel " & Round(DgrMinSec2DecDgr, 4)

End Function







Re: Writing result in Excel

Victor D

I found it, thank's to your help. The ideea is if you want to write in the cell you give a value to the function name (DgrMinSec2DecDgr), not writing ActiveCell....

Is working even with Double.