VBABEGINER
Well-known Member
- Joined
- Jun 15, 2011
- Messages
- 1,284
- Office Version
- 365
- Platform
- Windows
Public Function JumpCase(CellText As String) As String
Static REX As Object '<-- RegExp
Static REX2 As Object '<-- RegExp
Dim rexMatch As Object '<-- Match
Dim rexSubMatch As Variant
Dim strTemp As String
If REX Is Nothing Then
Set REX = CreateObject("VBScript.RegExp")
With REX
.Global = True
.IgnoreCase = False '???
.Pattern = "([A-Za-z0-9 ]*)(kV|to|NaOH|Na2CO3)([A-Za-z0-9 ]*)"
End With
Set REX2 = CreateObject("VBScript.RegExp")
With REX2
.Global = False
.IgnoreCase = False '???
.Pattern = "kV|to|NaOH|Na2CO3"
End With
End If
If REX.Test(CellText) Then
Set rexMatch = REX.Execute(CellText)(0)
For Each rexSubMatch In rexMatch.SubMatches
If Not REX2.Test(rexSubMatch) Then
strTemp = strTemp & UCase(rexSubMatch)
Else
strTemp = strTemp & rexSubMatch
End If
Next
Else
strTemp = CellText
End If
JumpCase = strTemp
End Function
I got this code from one of the Experts.
i called this function in -
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call JumpCase
End Sub
But i got this error,
"Argument not optional" and the yellow color strip comes on above i coloured.
Can any one suggest, How this can be called, for test the code is suitable 4 my solution or not?