IREALLYambatman
Board Regular
- Joined
- Aug 31, 2016
- Messages
- 63
Hey guys.. so this is the first real VBA stript that I'm trying to put together and I keep getting the error "Object Required" When I try and use set in order to return a value to the main Sub? Help?
The First Sub calls the RegExHelper function that I'm trying to write like this..
The RegExHelper Function:
The First Sub calls the RegExHelper function that I'm trying to write like this..
Code:
StringToUseAfter = RegExHelper(StringToUseAfter, "J-FLAG", "") 'StringToWorkOn,PatternToSearchForWhatToReplaceItWith)StringToUseAfter = RegExHelper(StringToUseAfter, "MSD", "") 'StringToWorkOn,PatternToSearchForWhatToReplaceItWith)
StringToUseAfter = RegExHelper(StringToUseAfter, "MS", "") 'StringToWorkOn,PatternToSearchForWhatToReplaceItWith)
StringToUseAfter = RegExHelper(StringToUseAfter, "(?i).*\-[0-9]*.", "") 'StringToWorkOn,PatternToSearchForWhatToReplaceItWith)
StringToUseAfter = RegExHelper(StringToUseAfter, "(?i)ccv", "") 'StringToWorkOn,PatternToSearchForWhatToReplaceItWith)
StringToUseAfter = RegExHelper(StringToUseAfter, "(?i)ccb", "") 'StringToWorkOn,PatternToSearchForWhatToReplaceItWith)
The RegExHelper Function:
Code:
Public Function RegExHelper(StringToWorkOn As String, PatternToSearchFor As String, WhatToReplaceItWith As String) As String
Debug.Print StringToWorkOn
Debug.Print PatternToSearchFor
Debug.Print WhatToReplaceItWith
Dim strPattern As String: strPattern = PatternToSearchFor
Dim strReplace As String: strReplace = WhatToReplaceItWith
Dim myreplace As Long
Dim strInput As String
Dim Myrange As Range
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regex.Test(StringToWorkOn) Then
StringToWorkOn = regex.Replace(StringToWorkOn, strReplace)
Debug.Print StringToWorkOn
End If
Set regex = Nothing
Set RegExHelper = StringToWorkOn
End Function