将搜索结果显示在单独的页中该代码示例在工作表的列中搜索单词 (“Hello”)。一旦找到匹配的数据,就将其复制到另一个工作表(“Search Results”)中。 Sub FindMe() Dim intS As Integer Dim rngC As Range Dim strToFind As String, FirstAddress As String Dim wSht As Worksheet Application.ScreenUpdating = False intS = 1 'This step assumes that you have a worksheet named 'Search Results. Set wSht = Worksheets("Search Results") strToFind = "Hello" 'Change this range to suit your own needs. With ActiveSheet.Range("A1:C2000") Set rngC = .Find(what:=strToFind, LookAt:=xlPart) If Not rngC Is Nothing Then FirstAddress = rngC.Address Do rngC.EntireRow.Copy wSht.Cells(intS, 1) intS = intS + 1 Set rngC = .FindNext(rngC) Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress End If End With End Sub 删除单元格的一部分该程序搜索字符串值的范围,并删除单元格的一部分内容。在本例中,当字符“Y”或“N”通过一个或多个空格与文本正文分隔时,程序就会从该字符串中删除它。 Sub RemoveString() Dim sStr as String, cell as Range 'Change the worksheet and column values to suit your needs. For Each cell In Range("Sheet1!F:F") If cell.Value = "" Then Exit Sub sStr = Trim(Cell.Value) If Right(sStr, 3) = " Y" Or Right(sStr, 3) = " N" Then cell.Value = Left(sStr, Len(sStr) - 1) End If Next End Sub To remove the trailing spaces left by removing the Y or N, change: cell.Value = Left(sStr, Len(sStr) - 1) to cell.Value = Trim(Left(sStr, Len(sStr) - 1)) (责任编辑:admin) |