【发布时间】:2021-02-05 16:26:35
【问题描述】:
我正在使用位于此处的函数:
为了将度分秒值转换为小数。
很遗憾,我遇到了这个问题。
我发现没有这个例子那么简单:
Fill formula down till last row in column
另一方面,这个例子更适合我的情况
Finding the Last Row and using it in a formula
也不想成功。
我想知道我为什么会得到:
- 只显示第二行的结果
- 公式前面的“@”字符(我可以在栏中看到)。
那我的代码有什么问题?
Sub Sun()
Dim rng As Range, cell As Range
Dim wors As Worksheet
Set wors = ThisWorkbook.ActiveSheet
Dim lastRow As Long, LastRow2 As Long
lastRow = wors.Range("P" & wors.Rows.Count).End(xlUp).Row
LastRow2 = wors.Range("Q" & wors.Rows.Count).End(xlUp).Row
Set rng = wors.Range("P1:P" & lastRow)
wors.Columns("E").Copy
wors.Columns("P").PasteSpecial xlPasteValues
For Each cell In rng
cell = WorksheetFunction.Substitute(cell, " ", "° ", 1)
Next
Call Degree
Range("Q2:Q" & lastRow).Formula = "=ConvertDecimal (P" & LastRow2 & " )"
End Sub
而且还报错:
无效的过程调用或参数
,带调试:
xDeg = Val(Left(pInput, InStr(1, pInput, "°") - 1))
函数代码:
Function ConvertDecimal(pInput As String) As Double
'Updateby20140227
Dim xDeg As Double
Dim xMin As Double
Dim xSec As Double
xDeg = Val(Left(pInput, InStr(1, pInput, "°") - 1))
xMin = Val(Mid(pInput, InStr(1, pInput, "°") + 2, _
InStr(1, pInput, "'") - InStr(1, pInput, _
"°") - 2)) / 60
xSec = Val(Mid(pInput, InStr(1, pInput, "'") + _
2, Len(pInput) - InStr(1, pInput, "'") - 2)) _
/ 3600
ConvertDecimal = xDeg + xMin + xSec
End Function
如何将此公式拖到最后一行?
【问题讨论】:
标签: excel vba excel-formula