首页
/
每日頭條
/
科技
/
提取一段字符串
提取一段字符串
更新时间:2024-07-25 00:11:53

提取一段字符串?由于Excel表格在用戶編輯的時候,常常會存在不規範的操作,比如符号全角和半角之間的問題:,下面我們就來說一說關于提取一段字符串?我們一起去了解并探讨一下這個問題吧!

提取一段字符串(快速提取字符串中的時間)1

提取一段字符串

由于Excel表格在用戶編輯的時候,常常會存在不規範的操作,比如符号全角和半角之間的問題:

Cells(1,1)="自from 8:00 至to18:00"

其中":"又有半角,又有全角,提取時相對較為麻煩。

我的思路是提取所有數字,然後把它們轉換成時間格式。

Set b = CreateObject("scripting.dictionary") x = 1 a1 = 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中測試通過。

各位,有其它更好的方法嗎?

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2024 - www.tftnews.com All Rights Reserved