我相信新的Excel宏和VBA,和现在面临以下问题细胞提取关键词:Excel中:VBA宏从包含字符串
(1)I有一个数据组,其具有〜50,000行和11列。 (2)我需要从表格中提取行,基于某个关键字 - 它与特定列中存在的字符串相匹配。
(3)我已经从另一个堆栈溢出问题以下代码:
Sub testIt()
Dim r As Long, endRow as Long, pasteRowIndex As Long
endRow = 10 ' of course it's best to retrieve the last used row number via a function
pasteRowIndex = 1
For r = 1 To endRow 'Loop through sheet1 and search for your criteria
If Cells(r, Columns("B").Column).Value = "YourCriteria" Then 'Found
'Copy the current row
Rows(r).Select
Selection.Copy
'Switch to the sheet where you want to paste it & paste
Sheets("Sheet2").Select
Rows(pasteRowIndex).Select
ActiveSheet.Paste
'Next time you find a match, it will be pasted in a new row
pasteRowIndex = pasteRowIndex + 1
'Switch back to your table & continue to search for your criteria
Sheets("Sheet1").Select
End If
Next r
End Sub
(4)的列的单元被搜索具有“YourCriteria”当作为唯一的条目这工作完全正常。
(5)然而,在我的数据我有有“YourCriteria”嵌入其中
对于实施例的字符串:“YourCriteria” =“球”,并在一个特定的列中的单元(一个或多个)含有“狗玩球”,‘球差’等
我如何可以提取含有“YourCriteria行”?什么是需要修改的代码?
感谢
嗨cwx,请你解决我的疑问? – pranav
+1使用版本没有[开始]参数(它似乎从来没有对我工作正常),并包括> 0。 如果您希望标准忽略大小写,您还应该考虑使用vbTextCompare。例如。你可以匹配“YourCriteria”,“yourcriteria”,“yOurcrIteriA”等。 – Mikegrann
@pranav编辑:) – cxw