0

I want to edit a string that contains the following:

From

WEEK = '2'
Date_Number(3,4,5,6,7,8)
AND
Allowance='100'
AND
((End_Date<'2017-09-17 00:00:00'
AND

Saturday_Name)

to

WEEK = '2'
Date_Number(22,25,27,28,29)
AND
Allowance='100'
AND
((End_Date<'2017-09-17 00:00:00'
AND

Saturday_Name)

I am already thinking of using split string using multiple delimiters ('Date_Number(' and ')') but the problem would be the other ')' will be also be splitted into an array. Is there a way that I could get or even edit the value between it?

2
  • 1
    the third parameter is the limit Split(string, ")", 2) msdn.microsoft.com/en-us/library/6x627e5f. RegEx is another option stackoverflow.com/questions/22542834/… Commented Jun 20, 2017 at 0:16
  • Your answer works! Although the problems is I have to edit other similar text but different placement on the string. The Date_Number might be placed on the 5th row or any row for that matter. The limit will be non-compliant by that sequence Commented Jun 20, 2017 at 1:15

1 Answer 1

1

Not tested, but you can try this pattern Date_Number\(.*\)

Sub test()
    Dim str As String
    str = "WEEK = '2' ..."

    With CreateObject("VBScript.RegExp")
        .Pattern = "Date_Number\(.*\)"
        str = .Replace(str, "Date_Number(22,25,27,28,29)")
    End With
End Sub

How do I get regex support in excel via a function, or custom function?

Sign up to request clarification or add additional context in comments.

2 Comments

How do you execute with statements? It gives me an error saying that "activex component can't create object vba"
@MarcoM it should be in a Sub or Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.