1、汉字在前,数字在后面的情形。可以用MID,min, find三个函数来实现提取里面的数字。如图:在B2输入“=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&“0123456789”)),20)”
2 、把单元格里面所有的数字都提出来。可以使用宏。先打开VBA编辑器。工具——宏——visual basic 编辑器
3、在编辑器里点击插入——模块。在模块那里输入如下代码:
Function zzsz(xStr As String) As StringDim i As IntegerFor i = 1 To Len(xStr)If IsNumeric(Mid(xStr, i, 1)) Then zzsz = zzsz &Mid(xStr, i, 1)NextEnd Function
4、回到工作表,在B2单元格那里输入“=zzsz(A2)”。就可以用VBA把A2单元格里所有的数字都提取出来了,如图所示。
Excel怎么只提取表格中的数字
5、指定从第几个数组提取开始。也就是说在不连续的那些数字中,从第几次出现的数组开始提取。同样在模块那里输入如下代码:
Function GetNums(rCell As Range, num As Integer) As StringDim Arr1() As String, Arr2() As StringDim chr As String, Str As StringDim i As Integer, j As IntegerOn Error GoTo line1
Str = rCell.TextFor i = 1 To Len(Str)chr = Mid(Str, i, 1)If (Asc(chr) 《 48 Or Asc(chr) 》 57) ThenStr = Replace(Str, chr, “ ”)End IfNext
Arr1 = Split(Trim(Str))ReDim Arr2(UBound(Arr1))For i = 0 To UBound(Arr1)If Arr1(i) 《》 “” ThenArr2(j) = Arr1(i)j = j + 1End IfNext
GetNums = IIf(num 《= j, Arr2(num - 1), “”)line1:End Function
用VBA 很简单的,如果你将表的结构告诉我,我也可以替你写几句,例如:
先将sheet2 复制到sheet3
假定客户名都在第一列
在sheet3 中运行下面程序(工具——宏——visual basic编辑器)
Sub kk()
Dim ints As Integer
Dim ragc As Range
Dim stofind As String, firadd As String
Dim wors As Worksheet
Application.ScreenUpdating = False
Set wors = Worksheets("sheet1")
For ints = 2 To 1000
stofind = wors.Cells(ints, 1)
Set ragc = ActiveSheet.Range("A2:A800").Find(what:=stofind, lookat:=xlPart)
If Not ragc Is Nothing Then
firadd = ragc.Address
ragc.EntireRow.Select
Selection.Delete Shift:=xlUp
End If
Next ints
Application.ScreenUpdating = True
End Sub
表中剩下的就是不重复的客户
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)