It must be something previous as I removed the cells.select and then the next function got the same error.
The macro I wrote copies a number from the spreadsheet into a WRQ IBM 5250 Terminal Session which is our in-house data base. It pastes the number and then executes the search for the company the number is associated with. I then does several screen scrapes copying each piece of data back to the spreadsheet and so on. Here is the top half of the macro. Each CALL function then executes code farther down in the macro. What the simple thing I am trying to do is just replace the 18's in the dates to 2018 then eventually copy all the scraped data to another spreadsheet.
I think the error maybe because the macro originates from the WRQ session (where the macro is installed and executed) the when I tell it to do the next function in the spreadsheet it is still in the WRQ session. I think I need to get the macro to move over to the spreadsheet and then execute the replacing of the dates. Otherwise I need to just write a separate macro to do that.
Dim lRow As Long, lLastRow As Long
Dim oMyWorkBook As Object
Dim oMyWorkSheet As Object
'Set Currentcell = ActiveCell
'Dim rng As Range
On Error Resume Next
Set oMyWorkBook = GetObject("C:\Users\jleonar3\Documents\DisCompare\MMDDYY-SGCS.XLSM")
Set oMyWorkSheet = oMyWorkBook.Sheets("sheet1")
On Error GoTo 0
If oMyWorkSheet Is Nothing Then
MsgBox "Source workbook not found."
Exit Sub
End If
With oMyWorkSheet
.Activate
'--find last row of data in col B. xlUp = -4162
lLastRow = .Cells(.Rows.Count, "B").End(-4162).Row
'--step through each row
For lRow = 2 To lLastRow
'--paste policy number onto clipboard
.Cells(lRow, "B").Copy
'--call procedure that will lookup corresponding network number
' and paste it to clipboard
Call DoBPLTerminalSession
'--paste network number into columm C
.Cells(lRow, "C").Select
.Paste
Call DoSTARTTerminalSession
.Cells(lRow, "D").Select
.Paste
Call DoENDTerminalSession
.Cells(lRow, "E").Select
.Paste
Call DoPLANTerminalSession
.Cells(lRow, "F").Select
.Paste
Call DoTRANSDATETerminalSession
.Cells(lRow, "G").Select
.Paste
Call DoSTATETerminalSession
.Cells(lRow, "I").Select
.Paste
Next lRow
End With
oMyWorkBook.Activate
'ActiveSheet.UsedRange.Select
(macro stop here with Run time 424 error)
Selection.Replace What:="18", Replacement:="2018", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Selection.Replace What:="17", Replacement:="2017", LookAt:=xlPart, _
'SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
'ReplaceFormat:=False
'Range("A1").Select
End Sub