我有一个包含很多行的电子表格。我想要的是搜索N列中的每个单元格。如果单元格以“find”开头(希望它不区分大小写),则返回A列中的值(同一行)。例。如果N2以“查找”或“查找”或“查找”(或任何其他变体)开头,则返回A2。工作表是“Master”,我希望在不同的工作表上运行。我的Excel版本是2013年。
答案 0 :(得分:0)
下面会将A中的值打印到即时窗口。
Sub returnA()
With Sheets("Master")
For Each cell In .Range("N2:" & .Range("N2").End(xlDown).Address)
If UCase(Left(cell.Value, 4)) = "FIND" Then
Debug.Print .Cells(cell.Row, 1).Value
End If
Next
End With
End Sub
答案 1 :(得分:0)
这将返回所有行的A列中的值,在任何情况组合中以“find”开头。 修改:已更新,以便在Sheet1的第N列中查找值,并将列A结果粘贴到Sheet2列A。
Sub Find()
Dim rFoundAddress As Range
Dim sFirstAddress As String
Dim x As Long
x = 1
With ThisWorkbook.Worksheets("Sheet1").Columns(14)
Set rFoundAddress = .Find("find*", LookIn:=xlValues, LookAt:=xlWhole)
If Not rFoundAddress Is Nothing Then
sFirstAddress = rFoundAddress.Address
Do
ThisWorkbook.Worksheets("Sheet2").Cells(x, 1) = .Cells(rFoundAddress.Row, 1)
x = x + 1
Set rFoundAddress = .FindNext(rFoundAddress)
Loop While Not rFoundAddress Is Nothing And _
rFoundAddress.Address <> sFirstAddress
End If
End With
End Sub
它会找到与这些匹配:
但找不到符合: