stillwillyboy
Technical User
The following code works on my PC at home, but when I sent it to work to run, it keeps jumping to the error handling message. I have verified that the file does exist in the directory. When I step thru it (F8), it opens up the PRVY6EPI.csv file for corrections, steps thru the procedure, then executes “handler” without correcting any of the numbers. Thoughts? TIA, Bill
Sub CorrectClientNumberBeforeSendingToADP()
'this sub changes selected client numbers from 4 to 5 digits Application.ScreenUpdating = False Application.DisplayAlerts = False Application.StatusBar = "Changing Client Numbers"
Dim cell As Range
On Error GoTo handler
Workbooks.OpenText FileName:= _
"C:\ClientPayOutsource\Prvy6epi\PRVY6EPI.csv"
'Windows("PRVY6EPI.CSV").Activate
‘Range("C1").Select
Range("C65536").End(xlUp).Select
For Each cell In Selection
If cell.Value = 1583 Then 'correcting first employee
cell.Value = "15831"
Else
cell.Value = cell.Value
End If
If cell.Value = 1628 Then 'correcting second employee
cell.Value = "16281"
Else
cell.Value = cell.Value
End If
If cell.Value = 1655 Then 'correcting third employee
cell.Value = "16555"
Else
cell.Value = cell.Value
End If
If cell.Value = 2064 Then 'correcting fourth employee
cell.Value = "20642"
Else
cell.Value = cell.Value
End If
Next cell
Range("A1").Select
ActiveWorkbook.SaveAs FileName:= _
"C:\Program Files\Microsoft Office\Excel\OutsourceXfer\PRVY6EPI.CSV"
ActiveWorkbook.Close
Exit Sub
handler: MsgBox "The PRVY6EPI.CSV file does not currently exist." _
& "Most likely it was deleted from its folder. Reprocessing " _
& "will create the file. "
Application.ScreenUpdating = True
End Sub
Sub CorrectClientNumberBeforeSendingToADP()
'this sub changes selected client numbers from 4 to 5 digits Application.ScreenUpdating = False Application.DisplayAlerts = False Application.StatusBar = "Changing Client Numbers"
Dim cell As Range
On Error GoTo handler
Workbooks.OpenText FileName:= _
"C:\ClientPayOutsource\Prvy6epi\PRVY6EPI.csv"
'Windows("PRVY6EPI.CSV").Activate
‘Range("C1").Select
Range("C65536").End(xlUp).Select
For Each cell In Selection
If cell.Value = 1583 Then 'correcting first employee
cell.Value = "15831"
Else
cell.Value = cell.Value
End If
If cell.Value = 1628 Then 'correcting second employee
cell.Value = "16281"
Else
cell.Value = cell.Value
End If
If cell.Value = 1655 Then 'correcting third employee
cell.Value = "16555"
Else
cell.Value = cell.Value
End If
If cell.Value = 2064 Then 'correcting fourth employee
cell.Value = "20642"
Else
cell.Value = cell.Value
End If
Next cell
Range("A1").Select
ActiveWorkbook.SaveAs FileName:= _
"C:\Program Files\Microsoft Office\Excel\OutsourceXfer\PRVY6EPI.CSV"
ActiveWorkbook.Close
Exit Sub
handler: MsgBox "The PRVY6EPI.CSV file does not currently exist." _
& "Most likely it was deleted from its folder. Reprocessing " _
& "will create the file. "
Application.ScreenUpdating = True
End Sub