2014年10月29日 星期三

Excel VBA RegExp Function

Function reg(str As String, pattern As String)
    Set regEx = CreateObject("VBScript.RegExp")
    regEx.pattern = pattern
    regEx.Global = True
    regEx.IgnoreCase = True
    Set Matches = regEx.Execute(str)
   
    If Matches.Count = 0 Then
        reg = "Not Found"
    Else
        reg = Matches(0).Value
    End If
   
End Function

=CONCATENATE("CLM-",reg(B2, "\d\d\d"))

2014年10月15日 星期三

Excel Macro

Sub delete4857to5236()
'
' delete4857to5236 巨集
'
' 快速鍵: Ctrl+a
'
    Application.Goto Reference:="R4857:R5236"
    Selection.Delete Shift:=xlUp
    Rows("1:1").Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWindow.SmallScroll Down:=6
    Rows("1:10000").Select
    Selection.RowHeight = 18.00
    Range("A1").Select
    Selection.End(xlDown).Select
End Sub