由于Excel表格在用户感谢得时候,常常会存在不规范得操作,比如符号全角和半角之间得问题:
Cells(1,1)="自from 8:00 至to18:00"
其中":"又有半角,又有全角,提取时相对较为麻烦。
我得思路是提取所有数字,然后把它们转换成时间格式。
Set b = CreateObject("scripting.dictionary")x = 1a1 = Cells(1, 1) With CreateObject("VBscript.REGEXP") .Global = True .Pattern = "\d+" For Each a In .Execute(a1) b.Add x, a.Value x = x + 1 Next End With starttime = Format(b(1) & ":" & b(2), "hh:mm") endtime = Format(b(3) & ":" & b(4), "hh:mm")
以上代码在VBA中测试通过。
各位,有其它更好得方法么?