I've been working on this code for hours and changed many things and I'm still stuck. The code runs fine the first time then when I run it a second time I get the run time error-91......
I looked at many posts on this subject and have changed code but still can't figure it out.
Any help would be appreciated!!!
Brad
I looked at many posts on this subject and have changed code but still can't figure it out.
Code:
Sub TieOutTemp()
Dim strCheck As String
Dim lngAddress As Long
Dim strCursor As String
Dim lngRow As Long
Dim rng As Range
Dim objXLTemp As Object
Dim objWBtemp As Object
Const strTieOutTempPath As String = "C:\RNETTDTieOut\BaseFiles\TieOutTemp.xls"
Const strRNETFilePath As String = "C:\RNETTDTieOut\BaseFiles\i000#accepted_items#age_st_fncurr.xls"
If FileExists(strRNETFilePath) Then
FileCopy strRNETFilePath, strTieOutTempPath
End If
Set objXLTemp = CreateObject("Excel.Application")
objXLTemp.Workbooks.Open (strTieOutTempPath)
Set objWBtemp = objXLTemp.ActiveWorkbook
With objWBtemp
strCheck = .Sheets(1).Cells(1, 1).Value
If strCheck = "Best Buy" Then
For x = 1 To 6
.Sheets(1).Rows(x).Delete
Next x
End If
.Sheets(1).Range("A1").Value = "Subtotal"
.Sheets(1).Range("B1").Value = "Status"
.Sheets(1).Range("C1").Value = "Carrier"
.Sheets(1).Range("D1").Value = "State"
.Sheets(1).Range("E1").Value = "Balance"
.Sheets(1).Range("F1").Value = "Dollars"
.Sheets(1).Range("F1").Value = "D/C"
.Sheets(1).Range("G1").Value = "Dollars"
.Sheets(1).Range("H1").Value = "TotalItems"
.Sheets(1).Range("I1").Value = "Units"
.Sheets(1).Range("J1").Value = "B/C"
Set rng = .Sheets(1).Range("D1:D100").Find(What:="Carrier", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
objXLTemp.Goto rng, True
Else
MsgBox "You need to add the current date to the Data Validation Summary MASTER on the Exiting Code....."
GoTo Getout
End If
lngAddress = (ActiveCell.Row - 2) / 3
strCursor = "D4"
strCarrier = .Sheets(1).Range(strCursor).Value
For x = 1 To lngAddress
lngRow = (3 * x) + 1
strCursor = "D" & lngRow
.Sheets(1).Range(strCursor).Copy
strRange = "C" & (lngRow - 2) & ":C" & (lngRow - 1) & ""
.Sheets(1).Range(strRange).Select
.ActiveSheet.Paste
Next x
End With
Getout:
objWBtemp.Save
objWBtemp.Close
objXLTemp.Quit
Set objXLTemp = Nothing
Set objWBtemp = Nothing
End Sub
Any help would be appreciated!!!
Brad