Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1491|回复: 2

[已解决]求个VBA

[复制链接]
发表于 2013-1-26 23:53 | 显示全部楼层 |阅读模式
Book13.rar (8.28 KB, 下载次数: 10)
发表于 2013-1-27 01:15 | 显示全部楼层    本楼为最佳答案   
  1. Option Explicit

  2. Sub 提取数据()
  3.     Dim arr, result(), temp As Object, k&, i&, j&
  4.     Dim iRow&
  5.     iRow = Cells(Rows.Count, 1).End(xlUp).Row
  6.     arr = Range("a1:a" & iRow)
  7.     ReDim result(1 To iRow, 1 To 3)
  8.     Dim reg As Object
  9.     Set reg = CreateObject("VBScript.regExp")
  10.     With reg
  11.         .Global = True
  12.         .Pattern = "(\d+)/(\d+)/(\d+)"
  13.         For i = 1 To UBound(arr)
  14.             If .test(arr(i, 1)) Then
  15.                 k = k + 1
  16.                 Set temp = .Execute(arr(i, 1))
  17.                 For j = 1 To UBound(result, 2)
  18.                     result(k, j) = "'" & temp(0).Submatches(j - 1)
  19.                 Next
  20.             End If
  21.         Next
  22.     End With
  23.     Range("e1").Resize(k, 3) = result
  24.     Set reg = Nothing
  25.     MsgBox "提取完成"
  26. End Sub
复制代码
回复

使用道具 举报

发表于 2013-1-27 10:36 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-19 21:12 , Processed in 0.416382 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表