返回列表 上一主題 發帖

[發問] 如何在單元格抽取特定的文字?

[發問] 如何在單元格抽取特定的文字?

VBA.jpg

例如上圖,想抽取A欄特定的號碼如ABCD2685444,但置於文字的前後或中間,如何透過VBA把它們抽出來放於B欄?謝謝!!

http://blog.xuite.net/hcm19522/twblog/372861868

TOP

回復 1# leehom
模組中增加自訂函數
  1. Function GetSerialNumber(s As String) As String
  2.     Dim oMatch As Object
  3.     With CreateObject("vbscript.regexp")
  4.         '假設規則為 4個大寫英文+7個數字 的獨立單詞
  5.         .Pattern = "\b[A-Z]{4}[0-9]{7}\b"
  6.         Set oMatch = .Execute(s)
  7.     End With
  8.     If oMatch.Count > 0 Then GetSerialNumber = oMatch(0)
  9. End Function
複製代碼
B1填入 =GetSerialNumber(A1)
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

回復 3# stillfish00

謝謝啊!很棒!!:D

TOP

http://blog.xuite.net/hcm19522/twblog/372861868
hcm19522 發表於 2016-1-11 14:12


函數啊,學習一下,謝謝你啊!!

TOP

        靜思自在 : 太陽光大、父母恩大、君子量大,小人氣大。
返回列表 上一主題