[英]Excel 2010 VBA Match function is not finding a match
In Excel 2010, my MATCH statement below is not working. 在Excel 2010中,下面的MATCH语句不起作用。 The function should return the row number of a dataset identified by the datasetId (which should be unique) and 0 if the datasetId is not present.
该函数应返回由数据集ID标识的数据集的行号(应唯一),如果不存在数据集ID,则返回0。 Whether the datasetId is present in the first column or not, the function always goes to the second branch and returns 0
无论数据集ID是否出现在第一列中,该函数始终转到第二个分支并返回0
Function findDataset(dataWorksheet As Worksheet, datasetId As String) As Integer
If Not VBA.IsError(Application.Match(datasetId, dataWorksheet.Columns(1), 0)) Then
findDataset = Application.Match(datasetId, dataWorksheet.Columns(1), 0)
Else
findDataset = 0
End If
End Function
There is nothing fundamentally wrong with your function: 您的功能从根本上没有错:
Function findDataset(dataWorksheet As Worksheet, datasetId As String) As Integer
If Not VBA.IsError(Application.Match(datasetId, dataWorksheet.Columns(1), 0)) Then
findDataset = Application.Match(datasetId, dataWorksheet.Columns(1), 0)
Else
findDataset = 0
End If
End Function
Sub MAIN()
Dim ws As Worksheet
Dim id As String, n As Integer
Set ws = Sheets("Sheet1")
id = "XX"
n = findDataset(ws, id)
MsgBox n
End Sub
Works for me..............perhaps your match is not EXACT. 为我工作...........也许您的比赛不完全正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.