66chawger
asked on
Increment specific value in record
I have the need to locate all the instances of a certain value in a record with a file and increment that value
Example of record is SE*30*SOMETHING~
Below I know how to find the record and do simple replace functions, but cannot figure out how to increment the value. In this case I would want to increment the value 30 by 3.
Below is code I have written to do simple find and replace on the record string. Can this be modified to increment the value immediately following the "SE*" ?
'With ActiveDocument.Range.Find
' .MatchWildcards = True
' .Text = "\SE(\*[0-9]{2})\*[0-9A-z] {1,50}"
' .Replacement.Text = "SE\*30\*2"
' .Execute Replace:=wdReplaceAll
'End With
Example of record is SE*30*SOMETHING~
Below I know how to find the record and do simple replace functions, but cannot figure out how to increment the value. In this case I would want to increment the value 30 by 3.
Below is code I have written to do simple find and replace on the record string. Can this be modified to increment the value immediately following the "SE*" ?
'With ActiveDocument.Range.Find
' .MatchWildcards = True
' .Text = "\SE(\*[0-9]{2})\*[0-9A-z]
' .Replacement.Text = "SE\*30\*2"
' .Execute Replace:=wdReplaceAll
'End With
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
No, the 30 represents the value increment.
No, the 30 represents the value increment.
ASKER
Ok, thanks, just needed to change that to a 3. Worked great!
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for 66chawger's comment #a38369691
for the following reason:
Worked great, fast solution, excellent comments in the code example.
Accepted answer: 0 points for 66chawger's comment #a38369691
for the following reason:
Worked great, fast solution, excellent comments in the code example.
Glad to hear it worked for you...though, I'm not sure why you'd close the question out via accepting your comment as the solution as apposed to my comment http:#a38369469
I'd recommend accepting comment http:#a38369469 as the the answer...notwithstanding that the coded solution used an increment of 30 instead of 3 (due to me misreading the question)
:)
:)
ASKER
Sorry, I hope this gives you the points. This was my intention... my apologies
It's okay, oversights can happen...thanks!
ASKER
For the line below, does the 30 represent the value "30" I had in my original example for the SE record? If so, just want to clarify that this value can be 1-99.
strRecord = Left(strRecord, 3) & Trim(Str(Val(Mid(strRecord