Here is my code that is working fine. @Andreik code was of great help. Thank you.
$i = InputBox("Starting Number", "Enter the starting number", "", "")
$e = InputBox("Total lines", "How many lines?", "", "")
$var = 0
Do
ClipPut('') ; Clear the clipboard
$Nmbr = StringRight("000" & $i, 4)
MouseClick('', 450, $VP)
Sleep(600)
MouseClick('', 450, $VP)
Sleep(600)
Send('^c')
Sleep(100)
$sData = ClipGet() ; Get the copied text from the clipboard
Sleep(50)
$sData = StringRegExpReplace($sData, '(_+\d+(?:_+\d+)*)$', '______' & $Nmbr) ; Replace the pattern at the end of the string
ClipPut($sData) ; Put the modified string back into the clipboard
Sleep(50)
Send('^v')
Send('{ENTER}')
$i += 1
$var += 1
$VP += 17
If $VP > 900 Then
Send('{PGDN 2}')
$VP = 130
EndIf
Until $var >= $e