1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| Private Declare Function MessageBoxTimeout Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long, ByVal wlange As Long, ByVal dwTimeout As Long) As Long
Sub main() Dim C, X, Y MsgBox2 ("开始删除...") C = getCell() X = C(0) Y = C(1) Call process(X, Y) MsgBox ("已删除完成,请确认后保存!") End Sub
'在当前活动工作簿的第一张sheet的前两行找到“投诉内容”的单元格 '返回值为数组:[0]为行,[1]为列 Function getCell() For Each cell In ActiveWorkbook.Worksheets(1).Range("a1:az2") If cell.Value = "投诉内容" Then getCell = Array(cell.Row, cell.Column): Exit For Next End Function
' 后期绑定vb正则对象,调用replace()方法把手机号去掉 Function process(X, Y) Dim re, lastRow lastRow = Cells(Rows.Count, Y).End(xlUp).Row '最后非空一行 Set re = CreateObject("VBscript.RegExp") re.Global = True re.Pattern = "1[3-9]\d{9}[,,.。/、\\]?" '手机号,及后面可能出现的一个字符 For Each cell In ActiveWorkbook.Worksheets(1).Range(Cells(X + 1, Y), Cells(lastRow, Y)) '下一行开始处理到最后一行 cell.Value = re.Replace(Replace(Trim(cell), vbCrLf, ""), "") '先去空,再去回车,再去re去手机号,最后设置cell的值 Next End Function
'1000以毫秒作为单位 Sub MsgBox2(str) MessageBoxTimeout 0, str, "", 0, 0, 1000 End Sub
|