Hello All Any Help is appreciated
I am getting the following code when I run my program with multiple excel workbooks open.
Run-Time Error '91':
Object variable or with block variable not set.
If I open just the workbook with the code it will run fine but when I open up other workbooks it will fail. Also if I close all workbooks and then reopen the program it will work.
Here is my code
it will fail at this line TestRange2.Find(EmpNumber).Activate
Any thoughts or help is appreciated.
Thanks
Dan
I am getting the following code when I run my program with multiple excel workbooks open.
Run-Time Error '91':
Object variable or with block variable not set.
If I open just the workbook with the code it will run fine but when I open up other workbooks it will fail. Also if I close all workbooks and then reopen the program it will work.
Here is my code
it will fail at this line TestRange2.Find(EmpNumber).Activate
PHP:
Sub ProcessRequestOff()
' Author:
' Description: This is used to change the availbilty on the TempServer sheet from the requestOff Form.
' ( changes only the approved request offs for the selected week)
Dim DateTemp, DateReqOff, DateTest As Date
Dim intReqCount(), intRow, TempRow, tempCol As Integer ' used to deterimine the number of request
Dim I As Integer ' Used for loops
Dim TestRange2, TestRange3 As Range
Dim strLastCell As String, intPos As Integer
Set WsTemp = Worksheets("tempServer")
Set WsReqOff = Worksheets("TempRequest")
WsTemp.Activate
WsTemp.Range("G1").Activate
DateTemp = ActiveCell.Value ' Set the start range for dates to be processed
DateTest = DateTemp + 6 ' Sets the end range for dates to be processed
WsReqOff.Activate
WsReqOff.Range("A1").Activate
intRow = WsReqOff.Range("A65536").End(xlUp).Row - 2 ' determines the number of request(must subtract one because of first row and 1 more because of option base 0)
If intRow = -1 Then ' bypass the rest of the code if there are no request off's
Else
ReDim intReqCount(intRow)
For I = 0 To intRow
WsReqOff.Activate
WsReqOff.Range("A2").Offset(I, 0).Activate
EmpNumber = ActiveCell.Value
ActiveCell.Offset(0, 3).Activate
DateReqOff = ActiveCell.Value
ActiveCell.Offset(0, 1).Activate
intPos = ActiveCell.Value
If intPos = MainCounter Then ' only change the current position being processed
WsTemp.Activate
BoolAval = False ' used to set availability to false
WsTemp.Range("A3").Activate
ActiveCell.End(xlDown).Activate
strLastCell = ActiveCell.Address
Set TestRange2 = Worksheets("tempserver").Range("A2", strLastCell)
Set TestRange3 = Worksheets("tempserver").Range("G1:M1")
TestRange2.Activate
TestRange2.Find(EmpNumber).Activate
TempRow = ActiveCell.Row
WsTemp.Range("F1").Activate
If DateReqOff >= DateTemp And DateReqOff <= DateTest Then ' only change the current request offs
TestRange3.Find(DateReqOff).Activate
tempCol = ActiveCell.Column
Cells(TempRow, tempCol).Select ' select the correct cell
ActiveCell.Value = BoolAval ' override value to "false"
Else
End If
Else
End If
Next
End If
End Sub
Thanks
Dan
Last edited: