Excel 2010
我试图让以下功能起作用。我需要给它一个工作表名称,一个列来搜索它的单元格和条件,当单元格内容匹配时,返回行号
Function findRow(worksheetname As Worksheet, searchColumn As Integer, condition As String) As Integer
Dim i As Integer ' Integer used in 'For' loop
findRow = 0
For i = 1 To Rows.count
If Worksheets(worksheetname).Cells(i, searchColumn).Value = condition Then
' A match has been found to the supplied string
' Store the current row number and exit the 'For' Loop
findRow = i
Exit For
End If
Next i
End Function
试着像这样打电话:
row = findRow(Application.Worksheets(ClustersInfo), 1, clusters(clusterid))