- 帖子
- 8
- 主題
- 3
- 精華
- 0
- 積分
- 11
- 點名
- 0
- 作業系統
- Window 8
- 軟體版本
- OFFICE 2007
- 閱讀權限
- 10
- 性別
- 女
- 註冊時間
- 2014-11-7
- 最後登錄
- 2015-3-11
|
回復 stillfish00
如果我是想驗証我的excel order form sheet 裡的range (h19)customer post code ...
hildaliu 發表於 2014-11-18 21:49 
i just tried this code , is this correct or not?- Sub UK_Postcodes()
- Dim RegExp As Object, Collection As Object, RegMatch As Object
- Dim Myrange As Range, C As Range, Outstring As String
- Set RegExp = CreateObject("vbscript.RegExp")
- With RegExp
- .Global = False
- .Pattern = "^([A-Z]{1,2}\d(\d|[A-Z])?|GIR) \d[A-Z]{2}$"
- End With
- Set Myrange = Range("h19")
- Outstring = ""
- Set Collection = RegExp.Execute(ActiveCell.Value)
- For Each RegMatch In Collection
- Outstring = Outstring & RegMatch
- Next
- If Range("h19").Value <> "" And Range("h19").Value = Outstring Then
- MsgBox "Valid UK Postcode"
- Else
- MsgBox "Invalid UK Postcode"
- End If
- Set Collection = Nothing
- Set RegExp = Nothing
- Set Myrange = Nothing
- End Sub
複製代碼 |
|