从单元中提取特定的信息

我有一张表格S和P.在表格S中,我有几个以D2E开头的ID,在N列开始有几个ID从4开始。

我将包含4的ID与列L中的表P进行比较。如果它们匹配,则我将列A中的表P的ID写入列N.

在快照中,我有几个案例,我不能提取。 任何人都可以帮助我,我怎么能做到这一点

在工作表S中,我有一个像41035036_drw_000_draf的ID,在工作表PI中我能够find相应的D2E编号,并将其打印出来,但我希望将此编号打印在P列P的工作表S中。

我相信我需要修改rng.find函数。 我看它的前8个字符。 任何人都可以帮忙,我可以怎么做

以下是我的代码

Sub drwmatch() Dim sh1 As Worksheet, sh2 As Worksheet Dim cell As Range, cell2 As Range, lstcl As Variant, lstcl2 As Variant, rgFnd As Variant Dim n As Double, ID As String Dim a As String Dim b As Variant Set sh1 = ThisWorkbook.Sheets("S") Set sh2 = ThisWorkbook.Sheets("P") ' ID starts with number 4 ID = "4" lstcl = sh1.Range("N10000").End(xlUp).Row lstcl2 = sh2.Range("L10000").End(xlUp).Row 'comparing columns N and L in both sheets For Each cell In sh2.Range("L5:L" & lstcl2) For n = 5 To lstcl a = Left(sh1.Range("N" & n), 8) If cell = a Then 'the cell in column M next to the matching cell is equal to the 4xxxxxxx number cell.Offset(0, 1) = a 'the next cell in column N is equal to the A2C number in column A cell.Offset(0, 2) = cell.Offset(0, -11) End If Next Next 'test that each cell in the first sheet corresponds to the located results in the second sheet _ 'and pastes back the A2C number, using the Range.Find function For Each cell2 In sh1.Range("N5:N" & n) If Left(cell2, 1) = ID Then Set rgFnd = sh2.Range("M5:M" & lstcl2).Find(cell2.Value) If Not rgFnd Is Nothing Then cell2.Offset(0, 1) = sh2.Range(rgFnd.Address).Offset(0, 1) End If End If Next End Sub 

search前8个字符,你可以写你的发现这样的指令

 Set rgFnd = sh2.Range("M5:M" & lstcl2).Find(Left(cell2.Value, 8), lookat:=xlPart)