search单个项目如果多个项目每个单元格

我很新vba,但我现在有一些工作代码。 我执行这个代码,清除一张纸上的单元格,引用该张纸上的assembly号,在另一张纸上search该assembly号,将我想要的数据复制到该assembly号,并粘贴到原始纸上。

当代码查看电子表格数据库中的每个单元格只有一个程序集编号时,这适用于感兴趣的程序集编号。 但是,如果程序集编号与单元格的精确值不匹配(如果每个单元格有多个程序集,则会发生这种情况),则代码将向上传递该单元格,而不粘贴相关数据。

有没有办法在单元格内查看,并让macros识别程序集编号是否在单元内的程序集数组中?

有没有一个快速的方法来改变“如果表(”模板“)。单元格(我,8)。值=程序集然后”行,以便它不需要一个确切的价值?

Sub findstencil() '1. declare variables '2. clear old search results '3. find records that match search criteria and paste them Dim assembly As String 'Assembly number of interest, containts numbers, letters and dashes Dim finalrow As Integer 'determines last row in database Dim i As Integer 'row counter 'clears destination cells Sheets("Search").Range("A7:H15").ClearContents assembly = Sheets("Search").Range("A5").Value finalrow = Sheets("Stencils").Range("C5000").End(xlUp).Row For i = 5 To finalrow If Sheets("Stencils").Cells(i, 8).Value = assembly Then Sheets("Stencils").Cells(i, 3).Resize(1, 6).Copy Sheets("Search").Range("B15").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues End If Next i Sheets("Search").Range("A5").Select End Sub 

拿你的select…

像运营商

 If Cells(i, 3).Value Like "*" & AssemblyNumber & "*" Then 

模块级别的报表…

区分大小写

 Option Compare Binary 

不区分大小写

 Option Compare Text 

InStr函数

区分大小写

 If InStr(1, Cells(i, 3).Value2, AssemblyNumber, 0) > 0 Then 

不区分大小写

 If InStr(1, Cells(i, 3).Value2, AssemblyNumber, 1) > 0 Then 

查找方法

 Set SearchRange = Range(Cells(5, 3), Cells(finalrow, 3)) Set cl = SearchRange.Find( _ What:=AssemblyNumber, _ After:=SearchRange.Cells(1, 1), _ LookIn:=xlValues, _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False) If Not cl Is Nothing Then Sheets("Stencils").Cells(cl.Row, 3).Resize(1, 6).Copy Sheets("Search").Range("B15").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues End If 

正则expression式

正则expression式,当它变得真实复杂

如何在Microsoft Excel中使用正则expression式(正则expression式)在单元格内和循环中

自定义字符分析

如果你想,你甚至可以通过字符比较来做一个angular色。 我之前已经完成了这个工作来实现统计并find近似/最佳猜测匹配。

下面是一个例子,演示如何使InStr这样的function允许在匹配中容忍…

 Function InStrTolerant(InputString As String, MatchString As String, Optional CaseInsensitiveChoice = False, Optional Tolerance As Integer = 0) As Integer 'Similar to InStr, but allows for a tolerance in matching Dim ApxStr As String 'Approximate String to Construct Dim j As Integer 'Match string index j = 1 Dim Strikes As Integer Dim FoundIdx As Integer For i = 1 To Len(InputString) 'We can exit early if a match has been found If StringsMatch(ApxStr, MatchString, CaseInsensitiveChoice) Then InStrTolerant = FoundIdx Exit Function End If If StringsMatch(Mid(InputString, i, 1), Mid(MatchString, j, 1), CaseInsensitiveChoice) Then 'This character matches, continue constructing ApxStr = ApxStr + Mid(InputString, i, 1) j = j + 1 FoundIdx = i Else 'This character doesn't match 'Substitute with matching value and continue constructing ApxStr = ApxStr + Mid(MatchString, j, 1) j = j + 1 'Since it didn't match, take a strike Strikes = Strikes + 1 End If If Strikes > Tolerance Then 'Strikes exceed tolerance, reset contruction ApxStr = "" j = 1 Strikes = 0 i = i - Tolerance End If Next If StringsMatch(ApxStr, MatchString, CaseInsensitiveChoice) Then InStrTolerant = FoundIdx Else InStrTolerant = 0 End If End Function