怎么在EXCEL中查找某个字符前面的特定值(数字)

如题所述

第1个回答  2011-07-18
需要查询sheet2到sheet20的区域的话,用LOOKUP函数是不行的。你可以试一下我说的方法:
1)Alt+F11, "插入","模块"
2) 把下面的代码拷贝后保存。
Public Function GetPlace(name As String) As String
On Error GoTo err
Dim iSheet As Worksheet
Dim row As Integer
Dim col As Integer

For Each iSheet In Worksheets
If iSheet.name <> "Sheet1" Then
For row = 2 To 300
For col = 1 To 6
If iSheet.Cells(row, col).Value Like "*" & name & "*" Then
GoTo found
End If
Next col
Next row
End If
Next

found:
GetPlace = iSheet.Cells(1, col).Value
err:
End Function

3)在sheet1的B1输入公式:
=GetPlace(A1)
然后向下填充所有的单元格,内容就是你要查找的结果。
第2个回答  2011-07-18
查找某个字符前面的特定值(数字)?
详细点追问

比如说有一行摘要,“售给天赐利来不锈钢301板材1200吨”想在EXCEL表格中把1200这个数字给选出来

追答

假设数据在A列 在B1输入
方法1:=LOOKUP(9E+307,--MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&5^19)),ROW($1:$99)))
公式下拉

方法2:=IF(ISERROR(FIND("-",A1)),"","-")&MID(SUM(MID(101&A1,2+LARGE(ISNUMBER(-MID(1&A1,COLUMN(1:1),1))*COLUMN(1:1),ROW($1:$50)),1)*10^ROW($2:$51))%,2,15)

方法3:按ALT+F11,插入-模块,复制下列语句
Function SplitNumEng(str As String, sty As Byte)
Dim StrA As String
Dim StrB As String
Dim StrC As String
Dim i As Integer
Dim SigS As String
For i = 1 To Len(str)
SigS = Mid(str, i, 1)
If SigS Like "[a-zA-Z]" Then
StrA = StrA & SigS
ElseIf SigS Like "#" Then
StrB = StrB & SigS
Else
StrC = StrC & SigS
End If
Next i
Select Case sty
Case 1
SplitNumEng = StrA
Case 2
SplitNumEng = StrB
Case Else
SplitNumEng = StrC
End Select
End Function
比如你的数据在A1
BI输入 =SplitNumEng(A1,1) 表示提取字母
=SplitNumEng(A1,2) 表示提取数字
=SplitNumEng(A1,3)表示提取中文

本回答被提问者采纳
第3个回答  2011-07-18
用FIND函数
相似回答