gpt4 book ai didi

excel - 为什么我的函数可以在 Windows 上运行,但不能在 OS X 上运行?

转载 作者:行者123 更新时间:2023-12-03 02:29:57 25 4
gpt4 key购买 nike

这是我的功能:

Function FindLast(searchTerm As String) As Integer

Set cell = Worksheets("nameofsheet").Columns("A").Find(what:=searchTerm, searchorder:=xlByColumns, searchdirection:=xlPrevious)

If cell Is Nothing Then
Debug.Print ("Text was not found")
FindLast = 0
Else
Debug.Print ("found")
FindLast = cell.row
End If

End Function

它在 Windows 上运行得很好,但在 Mac 上却不行。我总是在单元格中收到 #REF! 错误。

最佳答案

the formula im using my function in looks like this: =SUM(INDIRECT("'sheetname'!C"&MATCH($C22;'sheetname'!$A:$A;0‌​)&":C"&FindLast($C22‌​))) – StB 11 mins ago

该错误不是由于您的代码造成的。这是因为INDIRECT()

Excel Mac UDF 中的

.Find 不起作用。它不会像我在上面的评论之一中提到的那样给您错误消息。它会给你0。这是另一个stackoverflow post这证实了同样的情况。

要使其工作,您必须使用如下所示的循环。

Function FindLast(searchTerm As String) As Integer
Dim oSht As Worksheet
Dim lastRow As Long, i As Long

On Error GoTo WHOA

Set oSht = Sheets("nameofsheet")

lastRow = oSht.Range("A" & oSht.Rows.Count).End(xlUp).Row

For i = 1 To lastRow
If oSht.Range("A" & i).Value = searchTerm Then
MsgBox "Value Found in Cell " & oSht.Range("A" & i).Address
FindLast = i
Exit Function
End If
Next i
Exit Function
WHOA:
MsgBox Err.Description
End Function

关于excel - 为什么我的函数可以在 Windows 上运行,但不能在 OS X 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com