hi,
i have an enquiry to ask about how to replace the last two numbers when the inputbox prompt out, currently my code is whenever the inputbox prompt out, key in the numbers then it will do the + num( num is a variable which user can key in the numbers). But now i need to replace the last two numbers instead of doing addition function( in my code) for the following output
Examples for current code
AJ_20170203_01 -> prompt out then type 15 then ->AJ_20170203_16 ( my current code is doing addition)
Examples for the output i need
AJ_20170203_01 -> input box prompt out then type 15 then -> AJ_20170203_15
i have an enquiry to ask about how to replace the last two numbers when the inputbox prompt out, currently my code is whenever the inputbox prompt out, key in the numbers then it will do the + num( num is a variable which user can key in the numbers). But now i need to replace the last two numbers instead of doing addition function( in my code) for the following output
Examples for current code
AJ_20170203_01 -> prompt out then type 15 then ->AJ_20170203_16 ( my current code is doing addition)
Examples for the output i need
AJ_20170203_01 -> input box prompt out then type 15 then -> AJ_20170203_15
Code:
Sub test()
Dim fn As String, txt As String, num As Integer, temp
fn = ThisWorkbook.Path + "\PaymentFile01.txt"
If fn = "False" Then Exit Sub
txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "_(\d+)(?=\|)"
num = InputBox("Give me some input")
myVal = Format$(.Execute(txt)(0).submatches(0) + num, "_00")
txt = .Replace(txt, myVal)
.Pattern = "(\r\n)+$"
Open Replace(fn, ".txt", ".txt") For Output As #1
Print #1, txt;
MsgBox "This is bathch No" & myVal
Close #1
End With
End Sub